我运行了以下代码:
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
文件:
#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从文件系统加载此上下文?
答案 0 :(得分:0)
您是否尝试过如下设置JndiObjectFactoryBean
?
<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>