0
這可能是非常基本的,但我堅持了幾個小時,所以請聽我說。Glassfish 4 JBDCRealm NameNotFoundException
我想在Eclipse中的Glassfish 4.0上的Java 7 Web應用程序中進行基於JDBCRealm的身份驗證。此博客post是用於配置JDBCRealm的參考。
web.xml中是遵循
<login-config>
<auth-method>FORM</auth-method>
<realm-name>MyJDBCRealm</realm-name>
<form-login-config>
<form-login-page>/login.html</form-login-page>
<form-error-page>/tologin.html</form-error-page>
</form-login-config>
</login-config>
當我啓動GlassFish服務器它清楚地寫在控制檯:
SEC1115: Realm [MyJDBCRealm] of classtype [com.sun.enterprise.security.ee.auth.realm.jdbc.JDBCRealm] successfully created.
但是,當我請求任何應用程序的資源,我得到這個例外
javax.naming.NamingException: Lookup failed for 'MyJDBCRealm' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: MyJDBCRealm not found]
與根源:
javax.naming.NameNotFoundException: MyJDBCRealm not found
at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:237)
at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:204)
...
這發生在這裏
public DataSource getDataSource() {
DataSource datasource = null;
try {
datasource = (DataSource) initialContext.lookup("MyJDBCRealm");
} catch (NamingException ex) {
ex.printStackTrace();
}
return datasource;
}
我要指出的是,Hibernate的成功連接到後端數據庫和表映射,並在GlassFish控制檯,我可以成功地ping JDBC連接池。