【问题标题】:How to config java.util.Properties as JNDI in Tomcat如何在 Tomcat 中将 java.util.Properties 配置为 JNDI
【发布时间】:2018-04-24 12:47:58
【问题描述】:

如何将属性文件内容配置到Tomcat中以通过JNDI进行恢复?类似于 DataSource,但在本例中是 Properties

Jetty 服务器我可以这样配置:

 <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


    【解决方案1】:

    因此,我创建了一个工厂,用于在 tomcat 中将 Properties 作为 JNDI 资源访问。 Properties as JNDI

    &lt;tomcat-install&gt;/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" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 2013-06-10
      • 2012-10-14
      • 1970-01-01
      • 2016-01-02
      • 1970-01-01
      • 2018-09-22
      相关资源
      最近更新 更多