我有一个项目(这将用作依赖项),它使用SpringBoot,并以以下方式从queues.properties文件填充POJO:
@Component
@PropertySource({"classpath:queues.properties"})
@ConfigurationProperties("queue")
public class QueuesConfig {
private String messagingBrokerXml;
private String messagingBrokerJolokia;
private String messagingBrokerApi;
private List<QueuesConfig.QueueModel> queues = new ArrayList();
public QueuesConfig() {
}
public String getMessagingBrokerXml() {
return this.messagingBrokerXml;
}
...通过在类路径上有一个"queues.properties“文件的父SpringBoot项目中拖动此依赖项,QueuesConfig对象将填充正确的值。
我目前正试图通过在Plain Spring项目中使用此依赖项来实现相同的行为。我可以确认PropertySource注释已“执行”,并且queues.properties文件是StandardServletEnvironment的一部分(是propertySourceList中的一个条目)。
问题是"ConfigurationPropertiesBindingPostProcessor“bean没有被注册(不是singletonObjects的一部分),因此应该填充POJO的代码没有被执行。
有什么解决方法吗?
非常感谢!
发布于 2017-10-18 22:30:40
尝试将此代码添加到父Spring @Configuration类中:
@EnableConfigurationProperties(QueuesConfig.class) 有关更多详细信息,请阅读Spring Boot文档的这一部分。这是几个屏幕的文本,但它是值得的;-)
它在您的测试应用程序中可能运行良好,因为您在@SpringBootApplication中使用了一些高级魔法:)
https://stackoverflow.com/questions/46811570
复制相似问题