如何在 Tomcat 中将 java.util.Properties 配置为 JNDI

How to config java.util.Properties as JNDI in Tomcat

如何将属性文件内容配置到 Tomcat 以通过 JNDI 恢复?像数据源,但在本例中它是 Properties.

Jetty server中我可以这样配置:

 <New id="props-users" class="org.eclipse.jetty.plus.jndi.Resource">
  <Arg>props/users</Arg>
  <Arg>
   <New class="java.util.Properties">
    <Put name="url">http://127.0.0.0:5984</Put>
    <Put name="schema">users</Put>
    <Put name="user">mary</Put>
    <Put name="password">secret</Put>
   </New>
  </Arg>
 </New>

Glassfish server中我可以这样配置:

<custom-resource factory-class="org.glassfish.resources.custom.factory.PropertiesFactory" description="Properties to CouchDb enviroment" res-type="java.util.Properties" jndi-name="props/users">
   <property name="url" value="http://127.0.0.0:5984"></property>
   <property name="schema" value="users"></property>
   <property name="user" value="mary"></property>
   <property name="password" value="secret"></property>
 </custom-resource>

Tomcat,有自定义的还是在盒子里实现的?

因此,我在 tomcat 中创建了一个工厂来访问作为 JNDI 资源的属性。 Properties as JNDI

<tomcat-install>/conf/server.xml

<GlobalNamingResources>

  <Resource auth="Container" description="Conexao clientes CouchDB" 
   name="props/myDS" 
   type="java.util.Properties"
   url="http://127.0.0.1:5984" 
   schema="mydatabase" 
   userName="admin" 
   password="secret123"
   factory="net.sf.jkniv.jaas.jndi.JndiPropertyFactory" />

web.xml 文件中

<resource-ref>
  <description>properties for connection<description>
  <res-ref-name>props/myDS</res-ref-name>
  <res-type>java.util.Properties</res-type>
  <res-auth>Container</res-auth> 
  <mapped-name>props/myDS</mapped-name>
</resource-ref>

context.xml 文件中

<Context path="/myapp" reloadable="true">

  <ResourceLink name="props/myDS"  global="props/myDS" type="java.util.Properties" />