如果我有一个来自 XML 文件的 PropertyPlaceholderConfigurer
,是否可以让我的 Spring @Configuration
将它用作它处理的所有 bean 的属性源?
@Configuration
@ComponentScan(value = { "x.y.z })
@ImportResource({ "classpath:remote-properties/applicationContext.xml",})
public class CoreConfiguration implements TransactionManagementConfigurer {
@Resource(name = "com.c.h.c.PropertyPlaceholderConfigurer")
public PropertyPlaceholderConfigurer pp;
@Bean
public PropertyPlaceholderConfigurer propertiesFactoryBean() {
return pp;
}
}
通过上面的代码,它永远不会在 pp
上遇到我的断点。如果删除 @Bean
和方法,我可以验证是否填充了 pp
。那么如何在配置中注册它呢?
最佳答案
我觉得自己很蠢。我的一个 @Value
注释中缺少一个右花括号。我无法想象我看过多少次却错过了它。
因此,在您使用 @ImportResource
的应用上下文中使用 PropertyPlaceHolderConfigurer
将毫无问题地工作。您甚至不需要将其作为 @Resource
引入。
关于java - 带有 Spring @Configuration 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10543578/