8000 improve redistemplate injection& fix http require class · Dream2Land/WxJava@5f67298 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f67298

Browse files
committed
improve redistemplate injection& fix http require class
improve redistemplate injection& fix http require class
1 parent 8a2e7ce commit 5f67298

File tree

2 files changed

+82
-55
lines changed

2 files changed

+82
-55
lines changed
Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,68 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<parent>
6-
<artifactId>wx-java-spring-boot-starters</artifactId>
7-
<groupId>com.github.binarywang</groupId>
8-
<version>3.9.3.B</version>
9-
</parent>
10-
<modelVersion>4.0.0</modelVersion>
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>wx-java-spring-boot-starters</artifactId>
7+
<groupId>com.github.binarywang</groupId>
8+
<version>3.9.3.B</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
1111

12-
<artifactId>wx-java-mp-spring-boot-starter</artifactId>
13-
<name>WxJava - Spring Boot Starter for MP</name>
14-
<description>微信公众号开发的 Spring Boot Starter</description>
12+
<artifactId>wx-java-mp-spring-boot-starter</artifactId>
13+
<name>WxJava - Spring Boot Starter for MP</name>
14+
<description>微信公众号开发的 Spring Boot Starter</description>
1515

16-
<dependencies>
17-
<dependency>
18-
<groupId>com.github.binarywang</groupId>
19-
<artifactId>weixin-java-mp</artifactId>
20-
<version>${project.version}</version>
21-
</dependency>
22-
<dependency>
23-
<groupId>redis.clients</groupId>
24-
<artifactId>jedis</artifactId>
25-
<scope>compile</scope>
26-
</dependency>
27-
<dependency>
28-
<groupId>org.springframework.data</groupId>
29-
<artifactId>spring-data-redis</artifactId>
30-
<version>${spring.boot.version}</version>
31-
<scope>provided</scope>
32-
</dependency>
33-
</dependencies>
16+
<dependencies>
17+
<dependency>
18+
<groupId>com.github.binarywang</groupId>
19+
<artifactId>weixin-java-mp</artifactId>
20+
<version>${project.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>redis.clients</groupId>
24+
<artifactId>jedis</artifactId>
25+
<scope>compile</scope>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.data</groupId>
29+
<artifactId>spring-data-redis</artifactId>
30+
<version>${spring.boot.version}</version>
31+
<scope>provided</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.jodd</groupId>
35+
<artifactId>jodd-http</artifactId>
36+
<scope>provided</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.squareup.okhttp3</groupId>
40+
<artifactId>okhttp</artifactId>
41+
<scope>provided</scope>
42+
</dependency>
43+
</dependencies>
3444

35-
<build>
36-
<plugins>
37-
<plugin>
38-
<groupId>org.springframework.boot</groupId>
39-
<artifactId>spring-boot-maven-plugin</artifactId>
40-
<version>${spring.boot.version}</version>
41-
</plugin>
42-
<plugin>
43-
<groupId>org.apache.maven.plugins</groupId>
44-
<artifactId>maven-source-plugin</artifactId>
45-
<version>2.2.1</version>
46-
<executions>
47-
<execution>
48-
<id>attach-sources</id>
49-
<goals>
50-
<goal>jar-no-fork</goal>
51-
</goals>
52-
</execution>
53-
</executions>
54-
</plugin>
55-
</plugins>
56-
</build>
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-maven-plugin</artifactId>
50+
<version>${spring.boot.version}</version>
51+
</plugin>
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-source-plugin</artifactId>
55+
<version>2.2.1</version>
56+
<executions>
57+
<execution>
58+
<id>attach-sources</id>
59+
<goals>
60+
<goal>jar-no-fork</goal>
61+
</goals>
62+
</execution>
63+
</executions>
64+
</plugin>
65+
</plugins>
66+
</build>
5767

5868
</project>

spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
2424
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
2525
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
26+
import redis.clients.jedis.Jedis;
2627
import redis.clients.jedis.JedisPool;
27-
import redis.clients.jedis.JedisPoolAbstract;
2828
import redis.clients.jedis.JedisPoolConfig;
2929
import redis.clients.jedis.JedisSentinelPool;
30+
import redis.clients.util.Pool;
3031

3132
/**
3233
* 微信公众号存储策略自动配置.
@@ -80,7 +81,7 @@ private WxMpConfigStorage defaultConfigStorage() {
8081
}
8182

8283
private WxMpConfigStorage jedisConfigStorage() {
83-
JedisPoolAbstract jedisPool;
84+
Pool<Jedis> jedisPool;
8485
if (StringUtils.isNotEmpty(redisHost) || StringUtils.isNotEmpty(redisHost2)) {
8586
jedisPool = getJedisPool();
8687
} else {
@@ -94,10 +95,26 @@ private WxMpConfigStorage jedisConfigStorage() {
9495
}
9596

9697
private WxMpConfigStorage redisTemplateConfigStorage() {
97-
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
98+
StringRedisTemplate redisTemplate = null;
99+
try {
100+
redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
101+
} catch (Exception e) {
102+
// TODO: handle exception
103+
}
104+
try {
105+
if (null == redisTemplate) {
106+
redisTemplate = (StringRedisTemplate) applicationContext.getBean("stringRedisTemplate");
107+
}
108+
} catch (Exception e) {
109+
// TODO: handle exception
110+
}
111+
if (null == redisTemplate) {
112+
redisTemplate = (StringRedisTemplate) applicationContext.getBean("redisTemplate");
113+
}
98114
WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
99115
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps,
100116
wxMpProperties.getConfigStorage().getKeyPrefix());
117+
101118
setWxMpInfo(wxMpRedisConfig);
102119
return wxMpRedisConfig;
103120
}
@@ -118,7 +135,7 @@ private void setWxMpInfo(WxMpDefaultConfigImpl config) {
118135
}
119136
}
120137

121-
private JedisPoolAbstract getJedisPool() {
138+
private Pool<Jedis> getJedisPool() {
122139
WxMpProperties.ConfigStorage storage = wxMpProperties.getConfigStorage();
123140
RedisProperties redis = storage.getRedis();
124141

0 commit comments

Comments
 (0)
0