简体   繁体   English

春季:在应用程序上下文之外使用PropertyPlaceholderConfigurer支持

[英]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.

相关问题 春天-应用程序上下文中的bean是否动态绑定到PropertyPlaceholderConfigurer? - spring — are beans in application context binded to PropertyPlaceholderConfigurer dynamically? 无法使用PropertyPlaceholderConfigurer在JNDI上下文中找到属性 - Unable to find property in JNDI context using PropertyPlaceholderConfigurer 如何使用弹簧消息PropertyPlaceholderConfigurer传递参数? - How to pass parameters using spring message PropertyPlaceholderConfigurer? 如何将tomcat context.xml参数值获取到Spring PropertyPlaceholderConfigurer中 - How to get tomcat context.xml Parameters values into spring PropertyPlaceholderConfigurer Spring MVC-从应用程序上下文外部访问静态资源 - Spring MVC - Access static resources from outside the application context 如何从外部应用程序检索Tomcat中加载的Spring上下文 - How to retrieve Spring context loaded in Tomcat from outside application Spring引导在servlet上下文之外获取应用程序基本URL - Spring boot get application base url outside of servlet context 在Spring中使用PropertyPlaceholderConfigurer创建具有不同值的多个类实例 - creating multiple instances of class with diffrent values using PropertyPlaceholderConfigurer in Spring 在Spring Boot中配置PropertyPlaceholderConfigurer - Configure PropertyPlaceholderConfigurer in Spring Boot Spring PropertyPlaceholderConfigurer破坏自动装配 - Spring PropertyPlaceholderConfigurer Breaking Autowire
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM