使用postgres驱动程序创建JDBCRealm

问题描述 投票:3回答:2

所以我正在尝试为我的应用程序创建一个JDBCRealm,而不是使用tomcat-users.xml中的用户。

我已将我的server.xml更改为如下所示:

   <Realm className="org.apache.catalina.realm.LockOutRealm">
    <!-- This Realm uses the UserDatabase configured in the global JNDI
         resources under the key "UserDatabase".  Any edits
         that are performed against this UserDatabase are immediately
         available for use by the Realm.  

    <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> -->


    <Realm className="org.apache.catalina.realm.JDBCRealm"
             debug="99"
             driverName="org.postgresql.Driver" 
             connctionURL="jdbc:postgresql://localhost:5432/MyDataBase"
             connectionName="xxxxxxxx"
             ConnectionPassword="xxxxxxxx"
             userTable="authUsers" userNameCol="name" userCredCol="password"
             userRoleTable="authRole" roleNameCol="role" />
  </Realm>

所以 - UserDatabaseRealm被注释掉了,而我放入了我的JDBCRealm元素。

但由于某种原因,当我启动我的tomcat时,我一直得到一个nullPointerException,它来自postgres驱动程序类:

org.apache.catalina.LifecycleException: Failed to start component [Realm[JDBCRealm]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:201)
at org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:120)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1109)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.startup.Catalina.start(Catalina.java:691)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:456)
Caused by: java.lang.NullPointerException
at org.postgresql.Driver.connect(Driver.java:232)
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:710)
at org.apache.catalina.realm.JDBCRealm.startInternal(JDBCRealm.java:788)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 17 more

我使用postgres 9.3的tomcat 7和我用于驱动程序的jar是postgresql-9.3-1100.jdbc4.jar。

任何想法为什么它不起作用?任何已知的驱动程序错误?或者它是我元素中的东西?

谢谢!

postgresql tomcat tomcat7 jdbcrealm server.xml
2个回答
2
投票

答案非常简单:

connctionURL="jdbc:postgresql://localhost:5432/MyDataBase"

在参数名称中找到拼写错误。

由于您未提供connectionURL参数,因此驱动程序无法正确初始化,因此异常。


0
投票
<JDBCRealm"
debug="99" driverName="org.gjt.mm.mysql.Driver" 
connectionURL="jdbc:mysql://localhost/authority?            
user=test;password=test" userTable="users"
userNameCol="user_name"
userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" /> 

请参阅以下链接以获取更多解释

https://tomcat.apache.org/tomcat-3.3-doc/JDBCRealm-howto.html

© www.soinside.com 2019 - 2024. All rights reserved.