tomcat容器启动流程
启动tomcat容器,加载web.xml,建立整个容器(Servlet容器,这里是tomcat吧)的上下文,ServletContext,这时web.xml有个监听器,就是ContextLoaderListener,监听到这个事件,就会去扫描spring配置文件,默认是applicationContext.xml文件(classpath,idea是Resource下),如果自定义,就应该如web.xml中的<context-param>标签那般配置,扫描这个指定的Spring配置文件,就会将文件中相应的bean加载,其中实现了ApplicationContextAware的bean类会去执行setApplicationContext()方法,将上下文自动初始化
Servlet监听器(Listener )用于监听一些重要事件(Event)的发生,监听器对象可以在事情发生前、发生后可以做一些必要的处理。目前Servlet2.4和JSP2.0总共有8个监听器接口和6个Event类。
Listener 详细解读:【Spring】1、Spring中的Listener
Spring的ApplicationContext
提供了支持事件和代码中监听器的功能。我们可以创建bean用来监听在ApplicationContext
中发布的事件。ApplicationEven
t类和在ApplicationContext
接口
中处理的事件,如果一个bean实现了ApplicationListener
接口,当一个ApplicationEvent
被发布以后,bean会自动被通知。
Event 详细解读:【Spring】9、Spring中的事件Event