Why two instances of spring bean controllers are created in a Spring MVC application?

不打扰是莪最后的温柔 提交于 2019-12-04 15:31:41
Himanshu Bhardwaj

You are loading the context twice.

  1. Using the dispatcherservlet servlet definition.

  2. Using the contextloader listener as I mentioned in the comment too. -> you don't need to do this step.

Have a look at this:

Why use context loader listener?

Spring beans are, by default, "Spring singleton". That means one instance per context. A web application typically has at least two contexts - the root one and the web one. Most likely you have the controller instantiated for both of those. @ComponentScan is the most likely fault - try adding filters that will exclude any controllers from the root context.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!