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>