Jim
Jim

Reputation: 19582

Tomcat: Have I messed up my jndi connection set up or what?

I am using Tomcat's 7 connection pool. My configuration is the following:
In server.xml:

<GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="jdbc_DS" auth="Container"   
              type="javax.sql.DataSource"  
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"  
              driverClassName="org.h2.Driver"  
              url="jdbc:h2:file:absolutePathtodatabase"  
              username="root" password=""  
              maxActive="20" maxIdle="10" maxWait="-1"  
              />
  </GlobalNamingResources>   

And in context.xml:

<ResourceLink name="jdbc/myDS"  
        global="jdbc_DS"  
        type="javax.sql.DataSource"/>    

It seems to work but I noticed the following:
In the attributes of resource here:global resources it doesn't mention factory as attribute of a Resource.Nevertheless I have defined it in server.xmland got no error.
What does this mean?Am I not using a org.apache.tomcat.jdbc.pool.DataSourceFactory factory here?

Upvotes: 0

Views: 712

Answers (2)

user207421
user207421

Reputation: 311018

But you aren't using a <Resource> in context.xml, you are using a <ResourceLink>, so whatever attributes a <Resource> may have in context.xml is irrelevant. The <ResourceLink> just has enough attributes to refer to the <Resource>, which is fully defined elsewhere, including its factory attribute.

Upvotes: 1

Andreas Dolk
Andreas Dolk

Reputation: 114817

The Tomcat 7 documentation tells us, that you're configuration is correct for using a data source factory:

The Tomcat Connection pool is configured as a resource described in The Tomcat JDBC documentation With the only difference being that you have to specify the factory attribute and set the value to org.apache.tomcat.jdbc.pool.DataSourceFactory

The documentation further mentions:

You MUST also define any other needed parameters using attributes on the Resource element, to configure the object factory to be used (if not known to Tomcat already), and the properties used to configure that object factory.

which is another hint, that the list of valid elements is not complete.

Upvotes: 0

Related Questions