在web application 调用Spring的Beanfactory
1)配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- 配置加载的bean factory xml -->
<param-value>
WEB-INF/applicationContext*.xml
classpath:applicationContext-datasource.xml
classpath:applicationContext-hibernate.xml
classpath:applicationContext-dao.xml
classpath:applicationContext-service.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
2)Jsp页面中调用spring
org.springframework.beans.factory.BeanFactory beanFactory = (org.springframework.beans.factory.BeanFactory)
pageContext.getServletContext().getAttribute(org.springframework.web.context.WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
3)Servlet中调用spring
ServletContext context = this.getServletContext();
org.springframework.beans.factory.BeanFactory beanFactory = (org.springframework.beans.factory.BeanFactory)
context.getAttribute(org.springframework.web.context.WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
4)ClassPath加载
ApplicationContext beanFactory = new ClassPathXmlApplicationContext(
new String[] { "applicationContext-datasource.xml",
"applicationContext-hibernate.xml",
"applicationContext-service-freemarker.xml",
"applicationContext-service.xml"
});
分享到:
相关推荐
Spring中ApplicationContext和beanfactory区别.rar
对于spring的ioc的简单通过xml配置bean完成初始化工作的实现。
1. 什么是 spring? 2. 使用 Spring 框架的好处是什么? 3. Spring 由哪些模块组成? 4. 核心容器(应用上下文) 模块 5. BeanFactory – BeanFactory 实现举例 6. XMLBeanFactory 7. 解释 AOP 模块 8. 解释 JDBC 抽象...
Spring 的配置文件:..........................................................................................................7 1.3.4 在配置中配置类:........................................................
所有在xml里配置的Bean标签最后都会转换为BeanDefinition对象存放在beanFactory里的beanDefinitionMap中。实例化完成的Bean对象存放在singletonObjects当中。 FileSystemXmlApplicationContext是加载磁盘里具体位置...
3.7. General Web Improvements ............................................................................... 19 3.8. WebSocket, SockJS, and STOMP Messaging ..............................................
2.4.1. 在XML里更为简单的声明性事务配置 2.4.2. 对Websphere 事务管理的完整支持 2.4.3. JPA 2.4.4. 异步的JMS 2.4.5. JDBC 2.5. Web层 2.5.1. Spring MVC合理的默认值 2.5.2. Portlet 框架 2.5.3. 基于...
2.4.1. 在XML里更为简单的声明性事务配置 2.4.2. 对Websphere 事务管理的完整支持 2.4.3. JPA 2.4.4. 异步的JMS 2.4.5. JDBC 2.5. Web层 2.5.1. Spring MVC合理的默认值 2.5.2. Portlet 框架 2.5.3. 基于...
3.7. General Web Improvements ............................................................................... 19 3.8. WebSocket, SockJS, and STOMP Messaging ..............................................
Spring的IoC容器之BeanFactory[定义].pdf
NULL 博文链接:https://lgd-java2eye.iteye.com/blog/756599
使用Spring的IOC完成保存客户的操作: 。 案例需求 相关知识点 案例代码. Spring 整合 WEB 项目 引入 spring-web.jar 包: Spring 中的工厂(容器): BeanFactory(过时): Spring 配置文件中提示的配置
使用Spring的IOC完成保存客户的操作: 。 案例需求 相关知识点 案例代码. Spring 整合 WEB 项目 引入 spring-web.jar 包: Spring 中的工厂(容器): BeanFactory(过时): Spring 配置文件中提示的配置
使用Spring的IOC完成保存客户的操作: 。 案例需求 相关知识点 案例代码. Spring 整合 WEB 项目 引入 spring-web.jar 包: Spring 中的工厂(容器): BeanFactory(过时): Spring 配置文件中提示的配置
Spring的BeanFactory的接口的中文解释
Spring3.0引入了众多Java开发者翘首以盼的新功能和新特性,如OXM、校验及格式化框架、REST风格的Web编程模型等。这些新功能实用性强、易用性高,可大幅降低Java应用,特别是JavaWeb应用开发的难度,同时有效提升...
this.beanFactory.setSerializationId(getId()); } GenericApplicationContext.getBeanFactory(){ return this.beanFactory= new DefaultListableBeanFactory();//创建一个beanFactory } } 3.准备bean工厂...
NULL 博文链接:https://bjameng.iteye.com/blog/1468057
从加载过程我们可以看到,首先从Servlet事件中得到ServletContext,然后可以读到配置好的在web.xml的中的各个属性值,然后ContextLoder实例化WebApplicationContext并完成其载入和初始化作为根上下文。当这个根上...