如何将JNDI上下文从文件系统加载到Spring? [英] How to load JNDI context from the file system into Spring?
本文介绍了如何将JNDI上下文从文件系统加载到Spring?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我运行了以下代码:
Hashtable<String, String> environment = new Hashtable<String,String>();
environment.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
environment.put( Context.PROVIDER_URL, "file:/C:/Users" );
Context context = new InitialContext( environment );
context.rebind("John", new Person("John", "Smith", 35, 'm'));
(Person
是javax.naming.Referenceable
对象),它生成了.bindings
文件:
(Person
is a javax.naming.Referenceable
object), which generated a .bindings
file:
#This file is used by the JNDI FSContext.
#Sun Jan 14 13:50:02 EST 2018
John/RefAddr/3/Content=m
John/ClassName=com.examples.jndi.Person
John/RefAddr/1/Type=lastName
John/RefAddr/1/Content=Smith
John/RefAddr/3/Encoding=String
John/RefAddr/1/Encoding=String
John/RefAddr/2/Type=age
John/RefAddr/2/Content=35
John/RefAddr/3/Type=gender
John/RefAddr/2/Encoding=String
John/RefAddr/0/Content=John
John/RefAddr/0/Type=firstName
John/RefAddr/0/Encoding=String
如何使用Spring从文件系统加载此上下文?
How do I use Spring to load up this context from the file system ?
推荐答案
您是否尝试过如下设置JndiObjectFactoryBean
?
Have you tried setting up the JndiObjectFactoryBean
as below?
<bean id="jndi" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiEnvironment">
<props>
<prop key="java.naming.factory.initial">com.sun.jndi.fscontext.RefFSContextFactory</prop>
<prop key="java.naming.provider.url">file:/C:/Users</prop>
</props>
</property>
...
</bean>
这篇关于如何将JNDI上下文从文件系统加载到Spring?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文