Skip to content

Commit fb9d1b2

Browse files
committed
将配置项提取到配置文件里
1 parent 4216600 commit fb9d1b2

File tree

3 files changed

+45
-21
lines changed

3 files changed

+45
-21
lines changed

src/main/java/com/github/config/MainConfig.java

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.config;
22

3+
import org.springframework.beans.factory.annotation.Value;
34
import org.springframework.context.annotation.Bean;
45
import org.springframework.context.annotation.Configuration;
56

@@ -11,34 +12,40 @@
1112
/**
1213
* Created by FirenzesEagle on 2016/5/30 0030.
1314
* Email:liumingbo2008@gmail.com
15+
*
16+
* @author FirenzesEagle
17+
* @author BinaryWang
1418
*/
1519
@Configuration
1620
public class MainConfig {
1721

18-
//TODO(user) 填写公众号开发信息
19-
//商站宝测试公众号 APP_ID
20-
protected static final String APP_ID = "";
21-
//商站宝测试公众号 APP_SECRET
22-
protected static final String APP_SECRET = "";
23-
//商站宝测试公众号 TOKEN
24-
protected static final String TOKEN = "";
25-
//商站宝测试公众号 AES_KEY
26-
protected static final String AES_KEY = "";
27-
28-
//商站宝微信支付商户号
29-
protected static final String PARTNER_ID = "";
30-
//商站宝微信支付平台商户API密钥(https://pay.weixin.qq.com/index.php/core/account/api_cert)
31-
protected static final String PARTNER_KEY = "";
22+
@Value("#{wxProperties.appid}")
23+
private String appid;
24+
25+
@Value("#{wxProperties.appsecret}")
26+
private String appsecret;
27+
28+
@Value("#{wxProperties.token}")
29+
private String token;
30+
31+
@Value("#{wxProperties.aeskey}")
32+
private String aesKey;
33+
34+
@Value("#{wxProperties.partener_id}")
35+
private String partenerId;
36+
37+
@Value("#{wxProperties.partener_key}")
38+
private String partenerKey;
3239

3340
@Bean
3441
public WxMpConfigStorage wxMpConfigStorage() {
3542
WxMpInMemoryConfigStorage configStorage = new WxMpInMemoryConfigStorage();
36-
configStorage.setAppId(MainConfig.APP_ID);
37-
configStorage.setSecret(MainConfig.APP_SECRET);
38-
configStorage.setToken(MainConfig.TOKEN);
39-
configStorage.setAesKey(MainConfig.AES_KEY);
40-
configStorage.setPartnerId(MainConfig.PARTNER_ID);
41-
configStorage.setPartnerKey(MainConfig.PARTNER_KEY);
43+
configStorage.setAppId(this.appid);
44+
configStorage.setSecret(this.appsecret);
45+
configStorage.setToken(this.token);
46+
configStorage.setAesKey(this.aesKey);
47+
configStorage.setPartnerId(this.partenerId);
48+
configStorage.setPartnerKey(this.partenerKey);
4249
return configStorage;
4350
}
4451

src/main/resources/applicationContext.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
4+
xmlns:util="http://www.springframework.org/schema/util"
45
xsi:schemaLocation="
56
http://www.springframework.org/schema/context
67
http://www.springframework.org/schema/context/spring-context.xsd
78
http://www.springframework.org/schema/beans
89
http://www.springframework.org/schema/beans/spring-beans.xsd
910
http://www.springframework.org/schema/aop
10-
http://www.springframework.org/schema/aop/spring-aop.xsd">
11+
http://www.springframework.org/schema/aop/spring-aop.xsd
12+
http://www.springframework.org/schema/util
13+
http://www.springframework.org/schema/util/spring-util.xsd">
1114

1215
<!-- 自动扫描com.github包 ,将带有注解的类 纳入spring容器管理 -->
1316
<context:component-scan base-package="com.github"/>
@@ -30,4 +33,6 @@
3033
<!-- 配置使Spring采用CGLIB代理 -->
3134
<aop:aspectj-autoproxy proxy-target-class="true"/>
3235

36+
<util:properties id="wxProperties" location="classpath:/wx.properties" />
37+
3338
</beans>

src/main/resources/wx.properties

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#公众号 APP_ID
2+
appid=
3+
#公众号 APP_SECRET
4+
appsecret=
5+
#公众号 TOKEN
6+
token=
7+
#公众号 AES_KEY
8+
aeskey=
9+
#微信支付商户号
10+
partener_id=
11+
#微信支付平台商户API密钥
12+
partener_key=

0 commit comments

Comments
 (0)