我先描述一下环境:
环境: - 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- datasource-examples-howto.html#MySQL_DBCP_Example
服务器.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>
上下文.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"/>
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>
当我提交用户名和密码时,出现以下异常:
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 bound in this Context. Unable to find [jdbc].
at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at org.apache.catalina.realm.DataSourceRealm.open(DataSourceRealm.java:394)
at org.apache.catalina.realm.DataSourceRealm.authenticate(DataSourceRealm.java:285)
at org.apache.catalina.realm.CombinedRealm.authenticate(CombinedRealm.java:146)
at org.apache.catalina.realm.LockOutRealm.authenticate(LockOutRealm.java:180)
at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:295)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:450)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
我没有尝试在不同的操作系统上设置环境来测试它是否是特定于 mac 的问题。
我错过了什么建议?我感谢您的帮助!谢谢你。