2
votes

My application is based of Spring MVC template.

I have configured my DataSource with the following tag in my context.xml:

<Resource name="jdbc/registrator" auth="Container" type="javax.sql.DataSource"
           maxActive="100" maxIdle="30" maxWait="10000"
           username="javauser" password="javauser" driverClassName="org.gjt.mm.mysql.Driver"
           url="jdbc:mysql://localhost:3306/registrator"/>

Am I right thinking this will cause Tomcat to create a server-wide instance of org.gjt.mm.mysql.Driver bean and make it available under "jdbc/registrator" name?

Should I also describe this resource in web.xml as told here http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#JDBC_Data_Sources? Probably this is not required if I use Spring framework?

How can I access this bean from Spring context configuration?

1

1 Answers

3
votes

Use the jee namespace for this (see C.2.3 The jee schema):

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/registrator"/>

That defines a bean called dataSource that represents your Tomcat datasource.

No need to add anything to web.xml.