tomcat - 在 context.xml 中配置 jdbcRealm

标签 tomcat jsf-2 jdbcrealm

<Context antiJARLocking="true" path="/NCellLive">
<Resource 
    name="jdbc/Gis_WebApp" 
    auth="Container"
    type="javax.sql.DataSource" 
    username="uname" 
    password="pword"
    driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" 
    url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=Gis_WebApp;SelectMethod=cursor;"
    maxActive="8" 
/>
    <Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
    driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
    connectionURL="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=Gis_WebApp;"
    connectionName="uname" connectionPassword="pword"
    userTable="app_user" userNameCol="username" userCredCol="password"
    userRoleTable="app_user_group" roleNameCol="groupname"/>  

</Context>

现在所有数据库连接都工作正常,但在我添加领域后抛出以下错误我已经在库中添加了 sqljdbc4.jar。

Jan 31, 2012 11:28:24 AM org.apache.catalina.realm.JDBCRealm authenticate
SEVERE: Exception performing authentication
java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:701)
    at org.apache.catalina.realm.JDBCRealm.authenticate(JDBCRealm.java:352)
    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:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    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:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1805)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

可能是什么问题?

最佳答案

Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

告诉您在您的类路径中找不到 sql 库。
它需要在您的 tomcat/lib 文件夹中。

来自doc :

To set up Tomcat to use JDBCRealm, you will need to follow these steps:

  1. If you have not yet done so, create tables and columns in your database that conform to the requirements described above.
  2. Configure a database username and password for use by Tomcat, that has at least read only access to the tables described above. (Tomcat will never attempt to write to these tables.)
  3. Place a copy of the JDBC driver you will be using inside the $CATALINA_HOME/lib directory. Note that only JAR files are recognized!
  4. Set up a element, as described below, in your $CATALINA_BASE/conf/server.xml file.
  5. Restart Tomcat 6 if it is already running.

关于tomcat - 在 context.xml 中配置 jdbcRealm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9075044/

相关文章:

tomcat - 在 Tomcat 自定义域中获取 session 对象

apache - Cookie 路径总是使用 Apache Tomcat 7 而不是 Tomcat 9 引用

java - 如何使用JSF 2.0 f :ajax option with . jsp页面

jsf-2 - JSF 多次调用 setter & getter

java - JSF2 : inject service objects to managedbean from Spring?

java - 无法传递参数apache shiro jsp servlet

java - 创建用于启动tomcat服务器的bat文件时出错

hibernate - Tomcat 忽略 persistence.xml

tomcat - 适用于 AWS 云的最佳应用服务器容器

java - 如何创建自定义 JDBCrealm?