Reputation: 418
I am using tomcat 8.5
, where war files are copied in webapps folder and are exploded. We have a app context files defined in conf/Catalina/localhost/
. I have a context defined in server.xml
like below
server.xml
<Host appBase="webapps" deployOnStartup="false" autoDeploy="false" name="localhost" unpackWARs="true">
<Context displayName="Application One" path="/app1" reloadable="true"/>
</Host>
app1.xml
<Context displayName="Application One" path="/app1" swallowOutput="true">
<Resource name="jdbc/APP1OS" auth="Container" type="javax.sql.DataSource"
driverClassName="com.mysql.cj.jdbc.Driver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
maxActive="100"
maxIdle="10"
maxWait="5000"
maxAge="60000"
username="username"
password="password"
url="jdbc:mysql://dbname:port/appint?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&characterSetResults=utf8&serverTimezone=UTC&socketTimeout=300000&useSSL=false&requireSSL=false&allowPublicKeyRetrieval=true"
testOnBorrow="true"
validationQuery="Select '1'"/>
</Context>
Then I get below issue:-
Caused by: java.sql.SQLException: Error creating delegate data source for 'JNDI: java:comp/env/jdbc/APP1OS'
Error looking up JNDI DataSource (not found).
If I change my server.xml to add resource definition in context then it works fine.
<Host appBase="webapps" deployOnStartup="false" autoDeploy="false" name="localhost" unpackWARs="true">
<Context path="/app1" swallowOutput="true">
Resource name="jdbc/APP1OS" auth="Container" type="javax.sql.DataSource"
driverClassName="com.mysql.cj.jdbc.Driver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
maxActive="100"
maxIdle="10"
maxWait="5000"
maxAge="60000"
username="username"
password="password"
url="jdbc:mysql://dbname:port/appint?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&characterSetResults=utf8&serverTimezone=UTC&socketTimeout=300000&useSSL=false&requireSSL=false&allowPublicKeyRetrieval=true"
testOnBorrow="true"
validationQuery="Select '1'"/>
</Context>
</Host>
Upvotes: 0
Views: 103