会话属性在Spring @RestControllers中不起作用

时间:2018-02-15 04:10:01

标签: spring lazy-initialization

我已将位置添加为会话属性,如下所示

SELECT * INTO #Temp2
FROM 
(
    SELECT c.name CName ,t.name tName,0 AS isSELECTED
    FROM Sys.Columns c
    INNER JOIN Sys.types t ON c.user_type_id = t.user_type_id
    WHERE object_name(object_id) = 'tblActor'
)k

但是当我在Spring Rest服务中使用它时,波纹给了我和例外 " org.hibernate.LazyInitializationException:无法初始化代理 - 没有会话"

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
    User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    com.blife.werp.model.User userSession = userRepository.findByUsername(user.getUsername());
    HttpSession session = request.getSession();
    session.setAttribute("user", userSession);
    session.setAttribute("username", user.getUsername());
    session.setAttribute("location",userSession.getLocation());
    try {
        userService.isloggedIn(true, userSession,request);
    } catch (Exception e) {
        e.printStackTrace();
    }
    redirectStrategy.sendRedirect(request, response, "/dashboard");
}

任何人都可以让我现在在我的代码示例中出现导致此错误的问题,如果"位置"属性已经在会话中为什么它给了我一个懒惰的初始化我不会通过任何存储库获取它。

0 个答案:

没有答案