我想知道如何在 Spring 3 中从远程 JNDI 获取对象。你在哪里指定 URL,你如何在上下文文件中设置它等等。我发现了一些分散的信息建议这是可能的,但没有关于如何为不同服务器上的 JNDi 执行此操作的单一来源。
最佳答案
例如,您可以使用 JndiObjectFactoryBean像这样的基本配置中的类:
<bean id="someId" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="yourLookupNameGoesHere" />
<property name="jndiEnvironment">
<props>
<prop key="java.naming.provider.url">yourRemoteServerGoesHere:PortGoesHere</prop>
<prop key="java.naming.factory.initial">yourNamingContextFactoryGoesHere</prop>
<prop key="java.naming.factory.url.pkgs">yourPackagePrefixesGoHere</prop>
<!-- other key=values here -->
</props>
</property>
<!-- other properties here-->
</bean>
然后您可以指定其他 environment properties根据需要,您还可以使用 the Spring jee schema 来简化您的配置.
关于java - 在 Spring 中访问远程 JNDI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10440379/