手写一个可在application.properties中进行配置的配置类
在开发时,很多时候需要通过动态的配置信息来对一些工具进行配置,或者第三方平台的整合配置也需要用到。
话不多说,上代码:
//既然是Component就不要忘了在启动类上添加@ComponentScan
@Component
//prefix内定义的字符就是在application.properties中配置字符的前缀
@ConfigurationProperties(prefix = "wx.config")
public class WeiXinConfig {
/**开发者微信号*/
private String wxNumber;
/**开发者ID*/
private String appId;
/**开发者密码*/
private String appSecret;
/**用来做验证的token*/
private String token;
/**消息加密密钥*/
private String encodingAesKey;
/**get set方法就省略了*/
application.properties中的配置信息:
wx.config.wxNumber=
wx.config.appId=
wx.config.appSecret=
wx.config.token=
wx.config.encodingAesKey=

浙公网安备 33010602011771号