0

我有一个项目(这将用作依赖项),它使用 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 的代码没有被执行。

有什么解决方法吗?

非常感谢 !

4

1 回答 1

0

尝试将其添加到您的父 Spring @Configuration 类中:

@EnableConfigurationProperties(QueuesConfig.class) 

有关更多详细信息,请阅读 Spring Boot 文档的这一部分。这是几个文本屏幕,但值得;-)

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-typesafe-configuration-properties

可能它在您的测试应用程序中运行良好,因为您在 @SpringBootApplication 中使用了一些高级魔法:)

于 2017-10-18T14:30:39.633 回答