For both ContextLoaderListener
and DispatcherServlet
, the contextConfigLocation
parameter is optional.
ContextLoaderListener
defaults to /WEB-INF/application.xml
, DispatcherServlet
defaults to /WEB-INF/servletname-servlet.xml
.
If you set these parameters explicitly, you should not set them to the same value. The ContextLoaderListener
and DispatcherServlet
should have contexts with different sets of bean definitions, since otherwise, as you say, the beans will be instantiated twice.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…