我使用GWT與SmartGWT的圖書館提出申請,我一個JBoss服務器上部署這個。爲了驗證我的用戶,我製作了一個JPA實體和一個ManagerBean。但是,當我嘗試在此ManagerBean中使用EntityManager時,我得到一個NullPointerException。 EntityManager適用於其他任何類,但不適用於AppUser類。從AppUserManagerBeanGWT:EntityManager的NullPointerException異常
代碼:
@PersistenceContext(unitName = "test")
private EntityManager em;
private Logger logger = Logger.getLogger("be.test.server.AppUserManagerBean");
public boolean checkUser(String username,String password){
logger.info("ENTITY MANAGER: " + em.toString());
AppUser user = null;
Query query = em.createQuery("SELECT OBJECT(a) FROM AppUser a WHERE a.username = :username AND a.password = :password");
query.setParameter("username", username);
query.setParameter("password", password);
錯誤日誌:
java.lang.NullPointerException
be.test.server.auth.AppUserManagerBean.checkUser(AppUserManagerBean.java:23)
be.test.server.auth.CustomAuthenticationProvider.authenticate(CustomAuthenticationProvider.java:29)
org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:130)
org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
org.springframework.security.authentication.ProviderManager.doAuthentication(ProviderManager.java:148)
org.springframework.security.authentication.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:48)
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:97)
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
我知道這可能是不足夠的信息,以便隨時問我更多的評論。
在此先感謝。
您的EntityManager如何使用數據庫憑證創建並初始化?它是否在XML配置? – 2013-03-18 10:07:10
我有一個persistence.xml文件,但數據源的規格是standalone.xml在JBoss文件夾=) – Crowlix 2013-03-18 10:08:11
哪一行源代碼的行'checkUser' 23? – 2013-03-18 10:11:51