1

有人可以告诉我如何在没有由 spring 加载的 java 类中获取由 spring porpertyconfigurer 加载的属性吗?我想写一个单例类实现

应用程序上下文感知

并检索属性值。还有其他更好的方法吗?或者 Spring 是否有任何实用程序类来获取加载的属性?

4

1 回答 1

1

The PropertyPlaceholderConfigurer is a BeanFactoryPostProcessor, a specialized utility for post-processing bean definitions, and as such it is only relevant to the bean factory itself. The use case you have in mind is just not covered by it, the PropertyPlaceholderConfigurer does not lend its properties to the ApplicationContext, nor does it have a getProperties() (or similar) method.

AFAIK, you will have to introduce some value-holder bean, that will hold the property value for you

于 2012-05-18T09:58:46.550 回答