spring加载顺序
加载顺序,借网上的图:
官方文档描述:
When a web application is deployed into a container, the following steps must be performed, in this order, before the web application begins processing client requests.
1、Instantiate an instance of each event listener identified by a <listener> element in the deployment descriptor.
2、For instantiated listener instances that implement ServletContextListener, call the contextInitialized() method.
3、Instantiate an instance of each filter identified by a <filter> element in the deployment descriptor and call each filter instance's init() method.
4、Instantiate an instance of each servlet identified by a <servlet> element that includes a <load-on-startup> element in the order defined by the load-on-startup element values, and call each servlet instance's init() method.
所以,加载的先后顺序,可能会出问题,如果在spring.xml配置中把Controller(属于DispatcherServlet内容)也加载了,就可能出现在spring-web.xml加载中,发现Controller已经加载,有些内容不再加载了。所以需要使用<context:component-scan....>等