2012-10-31 9 views
2

내 프로젝트에 spring4gwt을 사용하고 있습니다.세션의 널 포인터 예외

나는 다음과 같은 로그인 서비스 구현이 있습니다

@Service("loginService") 
public class LoginServiceImpl extends RemoteServiceServlet implements LoginService { 

    @Override 
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) 
    public UserBean checkUser(String userName, String password) throws Exception { 

     HttpSession httpSession = getThreadLocalRequest().getSession(); 

    } 
} 

내가 전화

loginService.checkUser("test","test") (호스트 모드에서) getThreadLocalRequest() 반환하는 대신 실제 세션의 NULL로, 나는 NullPointerException이 얻을.

아직 웹 모드로 시도하지 않았습니다.

왜 널 세션이 생깁니 까? spring4gwt와 관련이 있습니까?

+0

@Filburt : web.xml 파일에

: 여기 http://code.google.com/p/spring4gwt/issues/detail?id=2 해결책을 발견

ISN th의 GWT 키워드 관련성 없음 전자 제목? –

+0

태그에 포함되어 있으므로 제목에 단순히 필요하지 않습니다. – Filburt

+0

키워드'Session'은 어떤가요? 그것은 또한 태그에 있습니다. 어쨌든 .. –

답변

6

예, spring4gwt이기 때문에 다른 approch가 필요합니다.

<filter> 
    <filter-name>springRequestFilter</filter-name> 
    <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>springRequestFilter</filter-name> 
    <url-pattern>/your-url/*</url-pattern> 
</filter-mapping> 

과 대신 :

HttpSession httpSession = getThreadLocalRequest().getSession(); 

사용 :

ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); 
HttpSession httpSession = attr.getRequest().getSession(); 
+1

해결책을 게시 해 주셔서 감사합니다 :) 이것은 많은 도움이되었습니다! –