2014-01-16 65 views
2

所以我想爲我的應用程序創建一個JDBCRealm,而不是使用tomcat-users.xml中的用戶。用postgres驅動創建JDBCRealm

香港專業教育學院改變了我的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元素。

,但由於某種原因,我不斷收到一個NullPointerException當我開始我的tomcat, 原產於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 

我使用Tomcat 7的Postgres 9.3和我使用的驅動程序的jar PostgreSQL相關9.3-1100.jdbc4.jar。

任何想法,爲什麼它不會工作?這個驅動程序的任何已知的錯誤?或者它是我的元素?

謝謝!

+0

看起來像Tomcat正在向我傳遞'null' JDBC URL。 –

回答

2

答案很簡單可怕:

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

點在參數名的錯字。

由於您沒有提供connectionURL參數,驅動程序無法正確初始化,因此是例外。

+0

相當。像這些問題往往會被標記爲刪除,這裏我們有一個特色之一。 – Patrick