Skip to content

Commit b0ff3f0

Browse files
lkqmbinarywang
authored andcommitted
🐛 #1182 修复公众号spring-boot-starter jedis依赖丢失问题,并优化代码,方便直接注入子service对象
1 parent 2eb0aa5 commit b0ff3f0

File tree

2 files changed

+106
-29
lines changed

2 files changed

+106
-29
lines changed

spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<dependency>
3939
<groupId>redis.clients</groupId>
4040
<artifactId>jedis</artifactId>
41+
<scope>compile</scope>
4142
</dependency>
4243
<dependency>
4344
<groupId>org.projectlombok</groupId>
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package com.binarywang.spring.starter.wxjava.mp.config;
22

3-
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
4-
import me.chanjar.weixin.mp.api.WxMpService;
3+
import me.chanjar.weixin.mp.api.*;
54
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
6-
import org.springframework.beans.factory.annotation.Autowired;
7-
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
8-
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
5+
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
96
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
10-
import org.springframework.context.ApplicationContext;
117
import org.springframework.context.annotation.Bean;
128
import org.springframework.context.annotation.Configuration;
139

@@ -18,38 +14,118 @@
1814
*/
1915
@Configuration
2016
public class WxMpServiceAutoConfiguration {
21-
@Autowired
22-
private ApplicationContext ctx;
2317

2418
@Bean
2519
@ConditionalOnMissingBean
2620
public WxMpService wxMpService(WxMpConfigStorage configStorage) {
2721
WxMpService wxMpService = new WxMpServiceImpl();
2822
wxMpService.setWxMpConfigStorage(configStorage);
29-
registerWxMpSubService(wxMpService);
3023
return wxMpService;
3124
}
3225

33-
@ConditionalOnBean(WxMpService.class)
34-
public Object registerWxMpSubService(WxMpService wxMpService) {
35-
ConfigurableListableBeanFactory factory = (ConfigurableListableBeanFactory) ctx.getAutowireCapableBeanFactory();
36-
factory.registerSingleton("wxMpKefuService", wxMpService.getKefuService());
37-
factory.registerSingleton("wxMpMaterialService", wxMpService.getMaterialService());
38-
factory.registerSingleton("wxMpMenuService", wxMpService.getMenuService());
39-
factory.registerSingleton("wxMpUserService", wxMpService.getUserService());
40-
factory.registerSingleton("wxMpUserTagService", wxMpService.getUserTagService());
41-
factory.registerSingleton("wxMpQrcodeService", wxMpService.getQrcodeService());
42-
factory.registerSingleton("wxMpCardService", wxMpService.getCardService());
43-
factory.registerSingleton("wxMpDataCubeService", wxMpService.getDataCubeService());
44-
factory.registerSingleton("wxMpUserBlacklistService", wxMpService.getBlackListService());
45-
factory.registerSingleton("wxMpStoreService", wxMpService.getStoreService());
46-
factory.registerSingleton("wxMpTemplateMsgService", wxMpService.getTemplateMsgService());
47-
factory.registerSingleton("wxMpSubscribeMsgService", wxMpService.getSubscribeMsgService());
48-
factory.registerSingleton("wxMpDeviceService", wxMpService.getDeviceService());
49-
factory.registerSingleton("wxMpShakeService", wxMpService.getShakeService());
50-
factory.registerSingleton("wxMpMemberCardService", wxMpService.getMemberCardService());
51-
factory.registerSingleton("wxMpMassMessageService", wxMpService.getMassMessageService());
52-
return Boolean.TRUE;
26+
@Bean
27+
public WxMpKefuService wxMpKefuService(WxMpService wxMpService) {
28+
return wxMpService.getKefuService();
29+
}
30+
31+
@Bean
32+
public WxMpMaterialService wxMpMaterialService(WxMpService wxMpService) {
33+
return wxMpService.getMaterialService();
34+
}
35+
36+
@Bean
37+
public WxMpMenuService wxMpMenuService(WxMpService wxMpService) {
38+
return wxMpService.getMenuService();
39+
}
40+
41+
@Bean
42+
public WxMpUserService wxMpUserService(WxMpService wxMpService) {
43+
return wxMpService.getUserService();
44+
}
45+
46+
@Bean
47+
public WxMpUserTagService wxMpUserTagService(WxMpService wxMpService) {
48+
return wxMpService.getUserTagService();
49+
}
50+
51+
@Bean
52+
public WxMpQrcodeService wxMpQrcodeService(WxMpService wxMpService) {
53+
return wxMpService.getQrcodeService();
54+
}
55+
56+
@Bean
57+
public WxMpCardService wxMpCardService(WxMpService wxMpService) {
58+
return wxMpService.getCardService();
59+
}
60+
61+
@Bean
62+
public WxMpDataCubeService wxMpDataCubeService(WxMpService wxMpService) {
63+
return wxMpService.getDataCubeService();
64+
}
65+
66+
@Bean
67+
public WxMpUserBlacklistService wxMpUserBlacklistService(WxMpService wxMpService) {
68+
return wxMpService.getBlackListService();
69+
}
70+
71+
@Bean
72+
public WxMpStoreService wxMpStoreService(WxMpService wxMpService) {
73+
return wxMpService.getStoreService();
74+
}
75+
76+
@Bean
77+
public WxMpTemplateMsgService wxMpTemplateMsgService(WxMpService wxMpService) {
78+
return wxMpService.getTemplateMsgService();
79+
}
80+
81+
@Bean
82+
public WxMpSubscribeMsgService wxMpSubscribeMsgService(WxMpService wxMpService) {
83+
return wxMpService.getSubscribeMsgService();
84+
}
85+
86+
@Bean
87+
public WxMpDeviceService wxMpDeviceService(WxMpService wxMpService) {
88+
return wxMpService.getDeviceService();
89+
}
90+
91+
@Bean
92+
public WxMpShakeService wxMpShakeService(WxMpService wxMpService) {
93+
return wxMpService.getShakeService();
94+
}
95+
96+
@Bean
97+
public WxMpMemberCardService wxMpMemberCardService(WxMpService wxMpService) {
98+
return wxMpService.getMemberCardService();
99+
}
100+
101+
@Bean
102+
public WxMpMassMessageService wxMpMassMessageService(WxMpService wxMpService) {
103+
return wxMpService.getMassMessageService();
104+
}
105+
106+
@Bean
107+
public WxMpAiOpenService wxMpAiOpenService(WxMpService wxMpService) {
108+
return wxMpService.getAiOpenService();
109+
}
110+
111+
@Bean
112+
public WxMpWifiService wxMpWifiService(WxMpService wxMpService) {
113+
return wxMpService.getWifiService();
114+
}
115+
116+
@Bean
117+
public WxMpMarketingService wxMpMarketingService(WxMpService wxMpService) {
118+
return wxMpService.getMarketingService();
119+
}
120+
121+
@Bean
122+
public WxMpCommentService wxMpCommentService(WxMpService wxMpService) {
123+
return wxMpService.getCommentService();
124+
}
125+
126+
@Bean
127+
public WxMpOcrService wxMpOcrService(WxMpService wxMpService) {
128+
return wxMpService.getOcrService();
53129
}
54130

55131
}

0 commit comments

Comments
 (0)