Tomcat JNDI resource name aliases

半腔热情 提交于 2019-12-10 22:29:29

问题


Is it possible to create a JNDI tomcat resource with multiple names (synonyms, aliases)? Something like

<Resource
      name="jdbc/product-ds"
      alias="jdbc/product-cfg-ds"
      type="com.mchange.v2.c3p0.ComboPooledDataSource"
      ...
/>

I need this, because there are two modules which use the same DataSource, but with different JNDI name. The simplest solution will be to sync those names, but unfortunately it's not possible at the moment.


回答1:


You can do this. It took me a while to work out the correct sequence. What you need to do is define the jdbc/product-ds in your server.xml (tomcat/conf/server.xml) in the GlobalNamingResources section kind of like this:

    <GlobalNamingResources>
        <Resource name="jdbc/product-ds " auth="Container"
          type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
          url="jdbc:oracle:thin:@127.0.0.1:1521:mysid"
          username="scott" password="tiger" maxActive="20" maxIdle="10"
          maxWait="-1"/>
    </GlobalNamingResources>

Then you can rename this in your server context.xml (tomcat/conf/context.xml)

Like this:

<ResourceLink 
        name="jdbc/product-cfg-ds"
        global="jdbc/product-ds"
        type="javax.sql.DataSource"/>

The global name is then renamed for all applications deployed on the the server. I don't think the global jdbc/product-ds will be available in any application, if you did want it you'd need to add:

<ResourceLink 
        name="jdbc/product-ds"
        global="jdbc/product-ds"
        type="javax.sql.DataSource"/>


来源:https://stackoverflow.com/questions/26624612/tomcat-jndi-resource-name-aliases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!