ApplicationContext能以声明的方式创建,可以使用ContextLodaer接口及其实现,它有两个实现:ContextLoaderListener和ContextLoaderServlet, 注意ContextLoaderListener不能与servlet2.2兼容,下面是具体实现
xml 代码
<context-param> <param-name> contextConfigLocation</param-name> <param-value>/web-inf/applicationContex.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.contex.ContexLoaderLister</listener-class> </listener> <!—or use the ContextLoaderServlet instead of the above listener <servlet> <servlet-name>context</servlet-name> <servlet-class> org.springframework.web.contex.ContexLoaderServlet</servlet-class> </servlet>