Reputation: 693
I have been going over almost all the web.xml/context.xml related questions over the web but nowhere did i get a clear enough answer to my following question. This says that the resource-ref tag in web.xml is equivalent to Resource tag in context.xml. This says that resource-ref tag in web.xml looks up the Resource tag in context.xml. Now these two sound confusing specifically because both the links I have referred to are Tomcat doc links and still have seemingly contradictory statements. Any clarifications would be extremely helpful.
Upvotes: 3
Views: 4622
Reputation: 81
The "Resource" tag defines the resource and can be placed in a number of xml files that largely depend upon the deployment preferences. To get started I'd place a context.xml in the META-INF folder in the web app. This directory is at the same level in the web app as the WEB-INF folder an example being:-
META-INF/context.xml
<Context>
<Resource name="jdbc/TestDB" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/testdb"
username="dbuser"
password="dbpassword"
maxTotal="20" maxIdle="10" maxWaitMillis="-1"/>
</Context>
The above makes the resource available.
The resource-ref tag is used to refer to the resource to make it avaiable to your app. This can go in the web.xml file.
WEB-INF/web.xml
<web-app>
<!--- snipped -->
<resource-ref>
<description>Test DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
Both of these can be configured in other ways. I usually go with something like this then dabble.
Upvotes: 2