Spring容器应用到项目

1.管理Service对象和DAO对象

2.Listener:监听器(监听属性创建销毁),监听器中方便获得事件源。

    管理容器在项目中的生命周期。

配置Listener来管理ApplicationContext的生命周期。可以让spring容器随项目的启动(servletContext)而创建,随项目的关闭而销毁。

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

指定加载spring配置文件的位置:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
</context-param>

猜你喜欢

转载自blog.csdn.net/hellodake/article/details/82114107