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  那么久是需要配置下这个判断条件

 解决了

原文地址:https://www.cnblogs.com/java-synchronized/p/9675421.html