如何将java.util.properties构成tomcat中的jndi



如何将属性文件内容配置到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服务器我可以以这种方式配置:

<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资源。属性为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" />

最新更新