在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();
<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();
相关文章推荐
- 一个jar包里的网站
- 一个jar包里的网站之文件上传
- 一个jar包里的网站之返回对媒体类型
- 关于JSP配置文件web.xml加载顺序详解
- Spring中属性注入详解
- struts2 spring整合fieldError问题
- spring的jdbctemplate的crud的基类dao
- 读取spring配置文件的方法(spring读取资源文件)
- jsp web.xml文件的作用及基本配置
- java实现简单美女拼图游戏
- java基本教程之线程休眠 java多线程教程
- JSP开发中在spring mvc项目中实现登录账号单浏览器登录
- 基于Spring框架的Shiro配置方法
- Spring MVC中上传文件实例
- 实例讲解Java的Spring框架中的AOP实现
- 解析Java中如何获取Spring中配置的bean
- Spring的注解配置与XML配置之间的比较
- java Spring整合Freemarker的详细步骤
- Java 二维码,QR码,J4L-QRCode 的资料整理
- java当中的定时器的4种使用方式