您的位置:首页 > 编程语言 > Java开发

在WEB.xml文件中配置Spring容器

2015-06-08 19:02 246 查看
        <!-- 配置 Spring 配置文件的名称和位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>

<!-- 启动 IOC 容器的 ServletContextListener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

使用:   //1. 从 appication 域对象中得到 IOC 容器的实例
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(application);

//2. 从 IOC 容器中得到 bean
Person person = ctx.getBean(Person.class);

//3. 使用 bean
person.hello();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  web.xml spring