3

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.

Marko Vranjkovic
  • 6,481
  • 7
  • 49
  • 68
  • Not a proper answer to this question, but as a last-resort workaround you could simply define two datasources linking to the same database. I can't really find proper documentation on how to do specifically what you want yet, but I have a nagging gut feeling the solution is in the resource-ref configuration in the web.xml and not the actual Resource... – Gimby Oct 29 '14 at 08:55

1 Answers1

3

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"/>
Chris M
  • 1,058
  • 1
  • 15
  • 26