[英]Spring: Using PropertyPlaceholderConfigurer support outside of application context
My applications requirements mean that I need to create application beans manually at runtime and then add them to the application context. 我的应用程序需求意味着我需要在运行时手动创建应用程序bean,然后将它们添加到应用程序上下文中。
These beans belong to third party libraries so I cannot modify them eg a TibjmsConnectionFactory
这些bean属于第三方库,因此我无法修改它们,例如
TibjmsConnectionFactory
So my factory class that creates these beans needs to be provided with a Properties
object that will set username, password, connectionTimeouts etc 因此,需要为我创建这些bean的工厂类提供一个
Properties
对象,该对象将设置用户名,密码,connectionTimeouts等
Ideally I'd like to use Spring
's property support so I do not need to convert Strings to Integers etc 理想情况下,我想使用
Spring
的属性支持,因此不需要将String转换为Integers等。
Also, the Properties
provided to my factory class will not be the same Properties used for by the PropertyPlaceholderConfigurer
in my overall ApplicationContext
另外,提供给我的工厂类的
Properties
将与整个ApplicationContext
PropertyPlaceholderConfigurer
所使用的PropertyPlaceholderConfigurer
。
How do I achieve this, or is it even possible? 我如何实现这一目标,或者甚至有可能?
public class MyCustomFactoryStrategy {
@Override
public TibjmsConnectionFactory create(Properties properties) {
TibjmsConnectionFactory connectionFactory = new TibjmsConnectionFactory();
connectionFactory.setServerUrl(properties.getProperty("emsServerUrl")); // this is a string
connectionFactory.setConnAttemptCount(new Integer(properties.getProperty("connAttemptCount"))); // this is an integer
...
return connectionFactory;
}
Have a look in this post. 看看这篇文章。 I think it might be what you need.
我认为这可能是您所需要的。
[ PropertyPlaceholderConfigurer not loading programmatically [ PropertyPlaceholderConfigurer无法以编程方式加载
[1]: [1]:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.