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

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> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId> <artifactId>spring-boot-autoconfigure</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId> <artifactId>spring-boot-starter</artifactId>

View File

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

View File

@ -1,7 +1,7 @@
package com.ossez.wechat.demo.config; package com.ossez.wechat.demo.config;
import com.ossez.wechat.demo.enums.HttpClientType; 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.WxMpService;
import com.ossez.wechat.oa.api.impl.WxMpServiceHttpClientImpl; import com.ossez.wechat.oa.api.impl.WxMpServiceHttpClientImpl;
import com.ossez.wechat.oa.api.impl.WxMpServiceImpl; import com.ossez.wechat.oa.api.impl.WxMpServiceImpl;
@ -22,7 +22,7 @@ public class WxMpServiceAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public WxMpService wxMpService(WxMpConfigStorage configStorage, WxMpProperties wxMpProperties) { public WxMpService wxMpService(WxMpConfigStorage configStorage, WeChatOfficialAccountProperties wxMpProperties) {
HttpClientType httpClientType = wxMpProperties.getConfigStorage().getHttpClientType(); HttpClientType httpClientType = wxMpProperties.getConfigStorage().getHttpClientType();
WxMpService wxMpService; WxMpService wxMpService;
switch (httpClientType) { 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.enums.StorageType;
import com.ossez.wechat.demo.properties.RedisProperties; 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 com.google.common.collect.Sets;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -37,7 +37,7 @@ import java.util.Set;
public class WxMpStorageAutoConfiguration { public class WxMpStorageAutoConfiguration {
private final ApplicationContext applicationContext; private final ApplicationContext applicationContext;
private final WxMpProperties wxMpProperties; private final WeChatOfficialAccountProperties wxMpProperties;
@Bean @Bean
@ConditionalOnMissingBean(WxMpConfigStorage.class) @ConditionalOnMissingBean(WxMpConfigStorage.class)
@ -115,8 +115,8 @@ public class WxMpStorageAutoConfiguration {
} }
private void setWxMpInfo(WxMpDefaultConfigImpl config) { private void setWxMpInfo(WxMpDefaultConfigImpl config) {
WxMpProperties properties = wxMpProperties; WeChatOfficialAccountProperties properties = wxMpProperties;
WxMpProperties.ConfigStorage configStorageProperties = properties.getConfigStorage(); WeChatOfficialAccountProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
config.setAppId(properties.getAppId()); config.setAppId(properties.getAppId());
config.setSecret(properties.getSecret()); config.setSecret(properties.getSecret());
config.setToken(properties.getToken()); config.setToken(properties.getToken());

View File

@ -9,7 +9,6 @@ import org.springframework.boot.context.properties.NestedConfigurationProperty;
import java.io.Serializable; import java.io.Serializable;
import static com.ossez.wechat.demo.enums.StorageType.Memory; 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 * @author someone
*/ */
@Data @Data
@ConfigurationProperties(PREFIX) @ConfigurationProperties(prefix = "wechat.official-account")
public class WxMpProperties { public class WeChatOfficialAccountProperties {
public static final String PREFIX = "wx.mp";
/** /**
* 设置微信公众号的appid. * 设置微信公众号的appid.

View File

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