背景:
視圖解析器(我們用的是velocity)
報錯:
because of an existing model object of the same name
按照網上給的原因 :
設置了屬性exposeSessionAttributes為true之后,所有的session中的變量都會在傳給視圖(velocity模板)時被合並到model中。這時如果在控制器中使用了@sessionAttributes注解(會把session中指定的變量存到model中),在最后合並model的時候會報Cannot expose session attribute 'xxx' because of an existing model object of the same name異常。查看了AbstractTemplateView.java文件后,發現spring在合並的時候還判斷了allowSessionOverride這個屬性,如果為false,就會拋出上面提到的異常。所以這種情況下,還要在配置文件的viewResolver中添加allowSessionOverride屬性,value為true,這樣即使遇到重復的值,也會直接使用Map中的put方法將舊值覆蓋。
發現並不行 ,最后源代碼斷點看了下
OK 那么久是需要配置下這個判斷條件
解決了