0

我正在使用 GWT 和 SmartGWT 库来制作应用程序,并将其部署在 JBoss 服务器上。为了验证我的用户,我创建了一个 JPA 实体和一个 ManagerBean。但是,当我尝试在此 ManagerBean 中使用 EntityManager 时,我得到了 NullPointerException。EntityManager 适用于所有其他类,但不适用于 AppUser 类。

来自 AppUserManagerBean 的代码:

@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)

我知道这可能还不够信息,所以请随时在评论中向我询问更多信息。

提前致谢。

4

1 回答 1

2

确保 AppUserManagerBean 也由容器而不是您自己实例化。

于 2013-03-18T10:12:25.047 回答