1.属性文件类
@ConfigurationProperties(prefix = "xxx.elklog") public class ElkLogConfig { private String appName; private String instanceID; private String pointcutCtrl; private String pointcutDao; private String pointcutService;
2.配置类
@Configuration @EnableConfigurationProperties(ElkLogConfig.class) public class ElkLogConfiguration { private ElkLogConfig elkLogConfig; public ElkLogConfiguration(ElkLogConfig elkLogConfig) { this.elkLogConfig = elkLogConfig; }
application.yml
xxx.elklog: appName: app-demo instanceID: 1002
解决使用
@Autowired
private ElkLogConfig elkLogConfig;
elkLogConfig这个变量为空的问题。使用构造函数可以解决。