Context specific JNDI parameters problem in tomcat 6

前端 未结 3 1754
无人及你
无人及你 2021-02-14 18:56

I am having trouble using JNDI when two or more applications are deployed on Tomcat 6. Consider the following scenario: I have 2 webapps, where each web.xml contains one JNDI pa

相关标签:
3条回答
  • 2021-02-14 19:30

    Well, I was revisiting the JNDI territory again and encountered a similar use case. Now I succeeded.

    If you need to access plain JNDI variables in a Web application, they should be defined in the element of your web application. But the syntax for defining an environment entry in the context differs from the syntax that is to be used in the web app descriptor (see my original post). This is where my confusion started.

    In the context it should be like:

    For global variables I still presume {CATALINA_HOME}/conf/context.xml will be the place to put these Environment entries.

    See the docs at apache: http://tomcat.apache.org/tomcat-5.5-doc/config/context.html#Environment_Entries

    Anyway, thanks for your help!

    0 讨论(0)
  • 2021-02-14 19:53

    BTW,

    1. you do NOT need stuff in web.xml.
    2. you do not need to modify /tomcat6/conf/context.xml

    All you need is to put context.xml in your META-INF of WebContent directory inside war. The JNDI will be register automatically, and pool will be created on application load.

    Only optionally, you can put it in /tomcat6/conf/context.xml, but this will require restart of tomcat after each configuration change.

    Here is some good configuration for my sql. Important point is logAbandoned (to detect unclosed connections that were thrown out of pool by container, because your code forgot to close it). For validation query i suggest something to test your database table presence.

    <Resource name="jdbc/NAME" auth="Container" type="javax.sql.DataSource"
                   maxActive="100" minIdle="10" maxWait="10000" removeAbandoned="true"
                   removeAbandonedTimeout="60" logAbandoned="true"
                   testWhileIdle="true" testOnBorrow="true" testOnReturn="false"
                   timeBetweenEvictionRunsMillis="5000"
                   validationQuery="SELECT 1" initialSize="10"
                   username="usrname" password="password"   
                   driverClassName="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://localhost:3306/databb?autoReconnect=true"/>
    
    0 讨论(0)
  • 2021-02-14 19:56

    From the example you give, I take it that "value A" should only be defined for (and accessible from) webapp A, and vice versa.

    One way to achieve is is to define them as context parameters (not JNDI resources) in each webapp's META-INF/context.xml file, as described here. If you do this, you can be sure each parameter is only reachable from its own webapp.

    0 讨论(0)
提交回复
热议问题