because of an existing model object of the same name


背景:

  視圖解析器(我們用的是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  那么久是需要配置下這個判斷條件

 解決了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM