My applications requirements mean that I need to create application beans manually at runtime and then add them to the application context.
These beans belong to third party libraries so I cannot modify them eg a TibjmsConnectionFactory
So my factory class that creates these beans needs to be provided with a Properties
object that will set username, password, connectionTimeouts etc
Ideally I'd like to use Spring
's property support so I do not need to convert Strings to Integers etc
Also, the Properties
provided to my factory class will not be the same Properties used for by the PropertyPlaceholderConfigurer
in my overall ApplicationContext
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
[1]:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.