在配置Tomcat的JDBCRealm的时候,有几个应该注意的地方
1. 数据库JDBC驱动应该放在${tomcat.home}/server/lib目录下,而不能放在webapps的lib目录下,二者的class loader不同
2. tomcat在启动时只会自动装载后缀为.jar的jar包,因此如果使用oracle9i的驱动,应把class12.zip改名为class12.jar
3. 最好将JDBCRealm的配置信息放在webapp的context配置文件中,而不要放在server.xml中
e.g.
<!-- ======================================================================= -->
<!-- This file is deployed to Tomcat 4.1.x using the "setup-tomcat" ant -->
<!-- task. You can also manually copy it to Tomcat's webapps directory. -->
<!-- ======================================================================= -->
<!-- To use Tomcat's MemoryRealm (in $CATALINA_HOME/conf/tomcat-users.xml)
simply comment out both of the Realm's below. MemoryRealm is the
default realm for all applications, specified in
$CATALINA_HOME/conf/server.xml.
To use Tomcat's JDBCRealm, JNDIRealm or JAASRealm, uncomment the
appropriate section below. All of these 3 realms require supplemental
drivers (JAR files) in $CATALINA_HOME/common/lib.
jdbc/mysql: http://www.mysql.com/downloads/api-jdbc-stable.html
- JAR: mysql-connector-java-2.0.14-bin.jar
jdbc/postgresql: http://www.postgresql.org/
- JAR: postgresql-jdbc3-7.3.jar
jndi/ldap: http://java.sun.com/products/jndi/index.html#download
- JAR: ldap.jar
jaas: http://free.tagish.net/jaas/index.jsp
- JAR: tagishauth.jar
NOTE: For the JAASRealm, you must also add the path to NTSystem.dll to
your $PATH environment variable.
-->
<!-- Simchronize-selfcare Application Context -->
<Context path="/simchronize-selfcare" docBase="simchronize-selfcare" debug="99" reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="simchronize_selfcare_log." suffix=".txt" timestamp="true"/>
<!--
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
driverName="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@10.168.195.62:1521:SIMCHRO"
connectionName="SIMCHR_24" connectionPassword="SIMCHR_24"
userTable="SIMCHR_SELFCARE_USERS" userNameCol="MSISDN" userCredCol="PASSWD"
userRoleTable="SIMCHR_SELFCARE_USER_ROLES" roleNameCol="ROLE" />
-->
<!-- NOTE: If you want to use a DataSourceRealm, the Resource must be a
global resource -->
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
driverName="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@10.168.195.62:1521:SIMCHRO"
connectionName="SIMCHR_24" connectionPassword="SIMCHR_24"
userTable="SIMCHR_SELFCARE_USERS" userNameCol="MSISDN" userCredCol="PASSWD"
userRoleTable="SIMCHR_SELFCARE_USER_ROLES" roleNameCol="ROLE" />
<Resource name="jdbc/simchronize" auth="Container" type="javax.sql.DataSource"/>