更新自述文件和属性文件绑定的方法

This commit is contained in:
YuCheng Hu 2023-01-12 07:55:53 -05:00
parent 5476c50dab
commit 7324306d77
6 changed files with 19 additions and 16 deletions

View File

@ -66,6 +66,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>

View File

@ -1,6 +1,6 @@
package com.ossez.wechat.demo.config;
import com.ossez.wechat.demo.properties.WxMpProperties;
import com.ossez.wechat.demo.properties.WeChatOfficialAccountProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@ -11,7 +11,7 @@ import org.springframework.context.annotation.Import;
* @author someone
*/
@Configuration
@EnableConfigurationProperties(WxMpProperties.class)
@EnableConfigurationProperties(WeChatOfficialAccountProperties.class)
@Import({ WxMpStorageAutoConfiguration.class, WxMpServiceAutoConfiguration.class })
public class WxMpAutoConfiguration {
}

View File

@ -1,7 +1,7 @@
package com.ossez.wechat.demo.config;
import com.ossez.wechat.demo.enums.HttpClientType;
import com.ossez.wechat.demo.properties.WxMpProperties;
import com.ossez.wechat.demo.properties.WeChatOfficialAccountProperties;
import com.ossez.wechat.oa.api.WxMpService;
import com.ossez.wechat.oa.api.impl.WxMpServiceHttpClientImpl;
import com.ossez.wechat.oa.api.impl.WxMpServiceImpl;
@ -22,7 +22,7 @@ public class WxMpServiceAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public WxMpService wxMpService(WxMpConfigStorage configStorage, WxMpProperties wxMpProperties) {
public WxMpService wxMpService(WxMpConfigStorage configStorage, WeChatOfficialAccountProperties wxMpProperties) {
HttpClientType httpClientType = wxMpProperties.getConfigStorage().getHttpClientType();
WxMpService wxMpService;
switch (httpClientType) {

View File

@ -2,7 +2,7 @@ package com.ossez.wechat.demo.config;
import com.ossez.wechat.demo.enums.StorageType;
import com.ossez.wechat.demo.properties.RedisProperties;
import com.ossez.wechat.demo.properties.WxMpProperties;
import com.ossez.wechat.demo.properties.WeChatOfficialAccountProperties;
import com.google.common.collect.Sets;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -37,7 +37,7 @@ import java.util.Set;
public class WxMpStorageAutoConfiguration {
private final ApplicationContext applicationContext;
private final WxMpProperties wxMpProperties;
private final WeChatOfficialAccountProperties wxMpProperties;
@Bean
@ConditionalOnMissingBean(WxMpConfigStorage.class)
@ -115,8 +115,8 @@ public class WxMpStorageAutoConfiguration {
}
private void setWxMpInfo(WxMpDefaultConfigImpl config) {
WxMpProperties properties = wxMpProperties;
WxMpProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
WeChatOfficialAccountProperties properties = wxMpProperties;
WeChatOfficialAccountProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
config.setAppId(properties.getAppId());
config.setSecret(properties.getSecret());
config.setToken(properties.getToken());

View File

@ -9,7 +9,6 @@ import org.springframework.boot.context.properties.NestedConfigurationProperty;
import java.io.Serializable;
import static com.ossez.wechat.demo.enums.StorageType.Memory;
import static com.ossez.wechat.demo.properties.WxMpProperties.PREFIX;
/**
* 微信接入相关配置属性.
@ -17,9 +16,8 @@ import static com.ossez.wechat.demo.properties.WxMpProperties.PREFIX;
* @author someone
*/
@Data
@ConfigurationProperties(PREFIX)
public class WxMpProperties {
public static final String PREFIX = "wx.mp";
@ConfigurationProperties(prefix = "wechat.official-account")
public class WeChatOfficialAccountProperties {
/**
* 设置微信公众号的appid.

View File

@ -35,8 +35,8 @@ spring.datasource.hikari.data-source-properties.elideSetAutoCommits=true
spring.datasource.hikari.data-source-properties.maintainTimeStats=false
# KEY
wx.mp.appId = appId
wx.mp.secret = @secret
wx.mp.token = @token
wx.mp.aesKey = @aesKey
wechat.official-account.app-id = appId
wechat.official-account.secret = secret
wechat.official-account.token = token
wechat.official-account.aes-key = aesKey