让我先描述一下环境:
环境: - mac os x(java build 1.6.0_35-b10-428-11M3811) - apache tomcat 7.0.30 - mysql 5.5.27 - tomcat/lib - > mysql-connector-java-5.1.22-bin.jar
我已成功实现了JDBCRealm并希望切换到DataSourceRealm,因为它建议用于生产环境.我使用基于表单的身份验证.
我做了这里描述的所有内容:http: //tomcat.apache.org/tomcat-7.0-doc/realm-howto.html#DataSourceRealm 和这里:http: //tomcat.apache.org/tomcat-7.0-doc/jndi-数据源-例子,howto.html#MySQL_DBCP_Example
server.xml中
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.DataSourceRealm"
dataSourceName="jdbc/proto" digest="SHA-256" roleNameCol="role"
userCredCol="password" userNameCol="name" userRoleTable="roles"
userTable="users"/>
</Realm>
Run Code Online (Sandbox Code Playgroud)
的context.xml
<Resource auth="Container"
driverClassName="com.mysql.jdbc.Driver"
maxActive="100" maxIdle="30" maxWait="10000"
name="jdbc/proto" password="proto" type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/proto" username="proto"/>
Run Code Online (Sandbox Code Playgroud)
WEB-INF/web.xml文件
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/proto</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Run Code Online (Sandbox Code Playgroud)
当我提交用户名和密码时,我得到以下例外:
Sep 18, 2012 9:38:32 PM org.apache.catalina.realm.DataSourceRealm open
SEVERE: Exception performing authentication
javax.naming.NameNotFoundException: Name [jdbc/proto] is not …Run Code Online (Sandbox Code Playgroud)