Skip to content

Commit

Permalink
将配置项提取到配置文件里
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Oct 19, 2016
1 parent 4216600 commit fb9d1b2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
47 changes: 27 additions & 20 deletions src/main/java/com/github/config/MainConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -11,34 +12,40 @@
/**
* Created by FirenzesEagle on 2016/5/30 0030.
* Email:[email protected]
*
* @author FirenzesEagle
* @author BinaryWang
*/
@Configuration
public class MainConfig {

//TODO(user) 填写公众号开发信息
//商站宝测试公众号 APP_ID
protected static final String APP_ID = "";
//商站宝测试公众号 APP_SECRET
protected static final String APP_SECRET = "";
//商站宝测试公众号 TOKEN
protected static final String TOKEN = "";
//商站宝测试公众号 AES_KEY
protected static final String AES_KEY = "";

//商站宝微信支付商户号
protected static final String PARTNER_ID = "";
//商站宝微信支付平台商户API密钥(https://pay.weixin.qq.com/index.php/core/account/api_cert)
protected static final String PARTNER_KEY = "";
@Value("#{wxProperties.appid}")
private String appid;

@Value("#{wxProperties.appsecret}")
private String appsecret;

@Value("#{wxProperties.token}")
private String token;

@Value("#{wxProperties.aeskey}")
private String aesKey;

@Value("#{wxProperties.partener_id}")
private String partenerId;

@Value("#{wxProperties.partener_key}")
private String partenerKey;

@Bean
public WxMpConfigStorage wxMpConfigStorage() {
WxMpInMemoryConfigStorage configStorage = new WxMpInMemoryConfigStorage();
configStorage.setAppId(MainConfig.APP_ID);
configStorage.setSecret(MainConfig.APP_SECRET);
configStorage.setToken(MainConfig.TOKEN);
configStorage.setAesKey(MainConfig.AES_KEY);
configStorage.setPartnerId(MainConfig.PARTNER_ID);
configStorage.setPartnerKey(MainConfig.PARTNER_KEY);
configStorage.setAppId(this.appid);
configStorage.setSecret(this.appsecret);
configStorage.setToken(this.token);
configStorage.setAesKey(this.aesKey);
configStorage.setPartnerId(this.partenerId);
configStorage.setPartnerKey(this.partenerKey);
return configStorage;
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/applicationContext.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">

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

<util:properties id="wxProperties" location="classpath:/wx.properties" />

</beans>
12 changes: 12 additions & 0 deletions src/main/resources/wx.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#公众号 APP_ID
appid=
#公众号 APP_SECRET
appsecret=
#公众号 TOKEN
token=
#公众号 AES_KEY
aeskey=
#微信支付商户号
partener_id=
#微信支付平台商户API密钥
partener_key=

0 comments on commit fb9d1b2

Please sign in to comment.