参考文档
使用示例
声明属性
import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; /** * */ @Data @ConfigurationProperties(prefix = "wx.miniapp") public class WxMaProperties { /** * 设置微信小程序的appid */ private String appid; /** * 设置微信小程序的Secret */ private String secret; /** * 设置微信小程序消息服务器配置的token */ private String token; /** * 设置微信小程序消息服务器配置的EncodingAESKey */ private String aesKey; /** * 消息格式,XML或者JSON */ private String msgDataFormat; }
注入并使用
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; /** **/ @Configuration @EnableConfigurationProperties(WxMaProperties.class) public class WxMaConfiguration { // 注入属性 @Autowired private WxMaProperties properties; }