Tomcat data source Configuration File Cache Problem and Solution

Source: Internet
Author: User

When there is only one datasource in the project, use the data source that comes with Tomcat 6 to connect to the database using the JNDI method, and the system starts normally.

Add another datasource to the same project (to use different databases), and use the data source of tomcat6 to connect to the database in JNDI mode. An exception is reported when the system is started: namenotboundexception (the last data source is not bound ).

Cause: After Tomcat 6 is deployed, the data source configuration file generated in the tomcat_home/CONF/Catalina/localhost/directory has not changed since the first deployment.

Solution: Delete the corresponding data source configuration file in the tomcat_home/CONF/Catalina/localhost/directory and redeploy the project to start the system normally.

 

The main configuration file code is attached:

JDBC. properties:

JDBC. datasource = Java: COMP/ENV/sssdatasource
JDBC. performance2 = Java: COMP/ENV/sssperformance2

 

ApplicationContext-db.xml:

<Bean id = "propertyconfigurer"
Class = "org. springframework. Beans. Factory. config. propertyplaceholderconfigurer">
<Property name = "locations">
<List>
<Value> classpath: JDBC. properties </value>
</List>
</Property>
</Bean>

<Bean id = "datasource"
Class = "org. springframework. JNDI. jndiobjectfactorybean">
<Property name = "jndiname">
<Value >$ {JDBC. datasource} </value>
</Property>
</Bean>
<Bean id = "performance2"
Class = "org. springframework. JNDI. jndiobjectfactorybean">
<Property name = "jndiname">
<Value >$ {JDBC. performance2} </value>
</Property>
</Bean>

 

The data source configuration file context. XML in the project META-INF:

<Context Path = "/SSS" docbase = "Sss"
DEBUG = "5"
Reloadable = "false"
Crosscontext = "true">
<Resourcelink name = "sssdatasource" Global = "sssdatasource" type = "javax. SQL. datasource"/>
<Resourcelink name = "sssdatasource2" Global = "sssdatasource2" type = "javax. SQL. datasource"/>
</Context>

 

Configure the data source in server. xml under Tomcat:

<Globalnamingresources>
<! -- Editable user database that can also be used
Userdatabaserealm to authenticate users
-->
<Resource Name = "userdatabase" auth = "Container"
Type = "org. Apache. Catalina. userdatabase"
Description = "user database that can be updated and saved"
Factory = "org. Apache. Catalina. Users. memoryuserdatabasefactory"
Pathname = "CONF/tomcat-users.xml"/>
<Resource
Name = "sssdatasource"
Type = "javax. SQL. datasource"
Password = "root"
Driverclassname = "com. MySQL. JDBC. Driver"
Maxidle = "2"
Maxwait = "5000"
Username = "root"
Url = "JDBC: mysql: // localhost: 3306/SSS? Useunicode = true & amp; characterencoding = UTF-8"
Maxactive = "4"/>
<Resource
Name = "sssperformance2"
Type = "javax. SQL. datasource"
Password = "root"
Driverclassname = "com. MySQL. JDBC. Driver"
Maxidle = "2"
Maxwait = "5000"
Username = "root"
Url = "JDBC: mysql: // localhost: 3306/sss2? Useunicode = true & amp; characterencoding = UTF-8"
Maxactive = "4"/>
</Globalnamingresources>

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.