【问题标题】:Spring JndiTemplate and parameterized JNDI lookup from contextSpring JndiTemplate 和从上下文中参数化的 JNDI 查找
【发布时间】:2010-05-27 14:01:43
【问题描述】:

如何在 Spring 应用程序上下文文件中表示 new JndiTemplate(properties).lookup(name),其中 name 是字符串变量?我可以用类似于以下的方式表达它,应用程序在检索 bean ID 时提供name

<util:properties id="applicationProperties"
    location="classpath:application.properties"/>

<jee:jndi-lookup id="connectionFactory"
    jndi-name="${name}"
    environment-ref="applicationProperties"
    resource-ref="false" />

【问题讨论】:

    标签: java spring jndi


    【解决方案1】:

    据我了解,您需要这样的东西:

    <bean id = "jndiTemplate" class = "org.springframework.jndi.JndiTemplate">
        <property name = "environment" ref = "applicationProperties" />
    </bean>
    
    <bean id = "objectFromJndi" factory-bean = "jndiTemplate" factory-method = "lookup"
        scope = "prototype" />
    

    -

    ApplicationContext ctx = ...;
    Object o = ctx.getBean("objectFromJndi", name);
    

    这会起作用,因为getBean 可以将参数传递给factory-method

    【讨论】:

    • 啊,如果是这样的话,我可能误解了这个问题。我似乎记得在 spring 3 中还支持抓取其他类的属性并将它们用作变量。
    猜你喜欢
    • 1970-01-01
    • 2012-02-18
    • 2013-04-09
    • 1970-01-01
    • 1970-01-01
    • 2021-05-10
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多