开发者

Error with spring session [ Cannot expose session attribute 'user' because of an existing model object of the same name]

Hi i am getting following error

javax.servlet.ServletException: Cannot expose session attribute 'user' because of an existing model object of the same name
    org.springframework.web.servlet.view.AbstractTemplateView.renderMerge开发者_高级运维dOutputModel(AbstractTemplateView.java:141)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)

Code

@Controller
@RequestMapping("/admin")
@SessionAttributes("user")
public class AdminHome {    
    @RequestMapping("home")
    public String homePage(HttpSession session, ModelMap map) {
        map.addAttribute(org.brahmaa.ads.util.impl.UserInfo.getPrincipal(session));
        return "admin/home";
    }
}


I suddenly got this exception as well. Turns out I had added this Freemarker property:

<property name="exposeSessionAttributes" value="true"/>


As far as I understand, map.addAttribute(org.brahmaa.ads.util.impl.UserInfo.getPrincipal(session)); extracts the user attribute from the session and puts it into model. @SessionAttriubtes instructs Spring to do the same automatically. Therefore they conflicts. You should use only one of these approaches, not both simultaneously.


I use property this in spring-boot

spring.freemarker.allow-session-override=true
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜