背景:

  视图解析器(我们用的是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方法将旧值覆盖。

 

发现并不行 ,最后源代码断点看了下

because of an existing model object of the same name

 

 OK  那么久是需要配置下这个判断条件

because of an existing model object of the same name

 解决了

 

相关文章:

  • 2021-09-16
  • 2021-11-12
  • 2021-08-22
  • 2021-12-07
  • 2021-12-02
  • 2022-12-23
  • 2022-02-03
猜你喜欢
  • 2022-12-23
  • 2021-08-11
  • 2021-06-15
  • 2021-07-26
  • 2021-11-15
  • 2021-11-30
  • 2021-11-04
相关资源
相似解决方案