org.springframework.aop ——Spring的面向切面编程,提供AOP(面向切面编程)的实现
org.springframework.asm——spring 2.5.6的时候需要asm jar包,spring3.0开始提供它自己独立的asm jar包
org.springframework.aspects——Spring提供的对AspectJ框架的整合
org.springframework.beans——所有应用都用到,包含访问配置文件,创建和管理bean等,是Spring IOC的基础实现。
org.springframework.context.support——Spring context的扩展支持,用于MVC方面
org.springframework.context——提供在基础IOC功能上的扩展服务,此外还提供许多企业级服务的支持,有邮件服务、任务调度、JNDI定位,EJB集成、远程访问、缓存以及多种视图层框架的支持。
org.springframework.core——Spring的核心工具包,其他包依赖此包
org.springframework.expression——Spring表达式语言
org.springframework.instrument.tomcat——Spring对tomcat连接池的集成
org.springframework.instrument——Spring对服务器的代理接口
org.springframework.jdbc——对JDBC 的简单封装
org.springframework.jms——为简化jms api的使用而做的简单封装
org.springframework.orm——整合第三方的orm实现,如hibernate,ibatis,jdo以及spring 的jpa实现
org.springframework.oxm——Spring对于object/xml映射的支持,可以让JAVA与XML之间来回切换
org.springframework.test——对JUNIT等测试框架的简单封装
org.springframework.transaction——为JDBC,HIBERNATE,JDO和JPA提供的一致性的声明式和简单编程式事务管理
org.springframework.web.portlet——Spring MVC的增强
org.springframework.web.servlet——对J2EE6.0 servlet3.0的支持
org.springframework.web.struts——整合struts框架的支持,可以更方便更容易的集成Struts框架。
org.springframework.web——包含Web应用开发时,用到Spring框架时所需的核心类,包括自动载入WebApplicationContext特性的类、Struts与JSF集成类、文件上传的支持类、Filter类和大量工具辅助类。
1.spring的7个模块
-
spring core模块
:包含BeanFactory
,BeanFactory是spring框架的核心,实现依赖注入【使个组件的依赖关系从代码中独立出来,使用配置文件即可实现这种依赖关系】和bean声明周期的管理
。
-
spring context模块
:该模块使spring成为框架,它通过配置文件将各个组件组合在一起,使组件之间可以正常访问。包括ApplicationContext
类,ApplicationContext继承BeanFactory接口并扩展功能。此外还有JSM
,JNDI访问
,远程调用
等内容。
-
DAO模块、ORM模块、AOP模块、web模块和MVC模块
。
2.spring的管理容器--BeanFactory和ApplicationContext
1.BeanFactory接口
:采用工厂模式,实例化和分发各种组件。实例化时自动根据配置文件applicationContext.xml(也可以其它名字)创建bean之间的依赖关系,<ref>来实现bean之间的依赖。
BeanFactory接口的5个方法,主要实现类:XMLBeanFactory
-
boolean containsBean(String str)
-
Object getBean(String str)
-
Object getBean(String str,Class)
-
boolean isSingleton(String str)
-
String[] getAliases(String str)
//别名
加载BeanFactory
InputStream is=new FileInputStream("WEB-INF\\applicationContext.xml");
XMLBeanFactory bf=new XMLBeanFctory(is);
MyBean mb=(MyBean)bf.getBean("mybean");
2. ApplicationContext接口
:
覆盖了BeanFactory的所有功能,一般使用ApplicationContext,资源少的时候才用BeanFactory.
实现类:ClassPathXmlApplication FileSystemXmlApplication XmlWebApplicationContext
其它功能
国家化支持、事件传播、对资源的访问
【spring可以通过Application.getResource()方法对资源(文件、web页面)进行访问】
加载ApplicationContext容器
ApplicationContext context=new FileSystemApplicationContext("applicationContext.xml");
MyBean mb=(MyBean)contxt.getBean("mybean");
在web.xml文件中配置
Listener接口方式
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class> org.springframework.web.context.ContextLoadLisener
</listener-class>
</listener>
servlet接口方式
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class> org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
WebApplicationContextUtils.getWebApplicationContext()
方法获得ApplicationContext的引用
3.依赖注入的两种方式
: 设值注入 构造函数注入
设值注入
备案中包含setter getter方法,配置
<bean id="mybean" class="org.cims201.MyBean" singleton="true" init-mehod="startInit" destroy-method="closeBean" depends-on="DealAction">
<property name="name">
<value>林建科</value>
</property>
<property name="password">
<value>null</value>
</property>
<property name="department">
<ref bean="department"><!--对应另一个bean的id-->
</property>
<property name="friedns">
<list>
<value>林建科1</value>
<value>林建科2</value>
</list>
</property>
<property name="friedns">
<set>
<value>林建科1</value>
<value>林建科2</value>
</set>
</property>
<property name="favorite">
<map>
<entry key="sport">
<value>篮球</value>
</entry>
<entry key="music">
<value>因为爱情</value>
</entry>
</map>
</property>
<property name="roommate">
<props>
<prop key="张">张教授</prop> <!--值为string类型-->
<prop key="林">林教授</prop> <!--值为string类型-->
</props>
</property>
构造函数注入
public class MyBean{
private String name;
private String sex;
private Department department;
public MyBean(String name,String sex,Department department){ //构造函数 this.name=name;
.......
}
}
配置如下,用 constructor-arg
【type
参数类型和index
指定参数顺序】
<bean id="mybean" class="org.cims201.MyBean" singleton="true" init-mehod="startInit" destroy-method="closeBean" depends-on="DealAction">
<constructor-arg type="java.lang.String" index="0">
<value>林科</value>
</constructor-arg>
<constructor-arg type="java.lang.String" index="1">
<value>男</value>
</constructor-arg>
<constructor-arg>
<ref bean="department">
</constructor-arg>
</bean>
<bean id="mybean" class="org.cims201.MyBean" > <!--另一个bean的配置-->
<property name="name">
<value>林克</value>
</property>
</bean>
分享到:
相关推荐
NULL 博文链接:https://lgd-java2eye.iteye.com/blog/756599
主要介绍了简单了解Spring中BeanFactory与FactoryBean的区别,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Spring中ApplicationContext和beanfactory区别.rar
Spring的BeanFactory的接口的中文解释
主要介绍了Spring BeanFactory和FactoryBean区别解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
spring之beanfactory 的一些基本知识与其关系使用
对BeanFactory的相关所有接口的功能的关键点进行了总结描述,中文版本
主要介绍了简单了解Spring beanfactory循环依赖命名重复2大属性,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
NULL 博文链接:https://364232252.iteye.com/blog/2369489
NULL 博文链接:https://ylxy3058.iteye.com/blog/2223489
主要给大家介绍了关于Spring中BeanFactory与FactoryBean接口的区别的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者使用Spring具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
Spring BeanFactory Spring IOC(控制翻转)/DI(依赖注入) Spring Proxy Spring AOP 面向切面编程 Spring与JDBC整合 Spring声明式事务 Spring与Hibernate整合 Spring与Struts整合
本篇文章主要介绍了Spring中BeanFactory解析bean详解 ,详细的介绍了使用BeanFactory对bean进行解析的实例,有兴趣的可以了解一下。
Spring中BeanFactory和ApplicationContext的区别 谈谈Spring IOC的理解,原理与实现? bean的生命周期,详细看上面 SpringBoot自动装配的过程的原理: spring的缓存; spring是如何解决的循环依赖; BeanFactory和...
Spring注解驱动开发第41讲——Spring IOC容器创建源码解析(一)之BeanFactory的创建以及预准备工作(合起来整个过程)
spring3中实例化BeanFactory的3中方法
《Spring揭秘》以幽默生动的语言、辅以有趣的故事和典故,循循善诱地阐述了Spring框架的方方面面。针对Spring框架的主要功能以及开发者们遇到最多的问 题,首先介绍问题的相关背景,然后逐条进行深度剖析,最后通过...
Spring教程 1 Spring框架概述 3 Spring是什么? 3 Spring的历史 4 Spring的使命(Mission Statement) 4 Spring受到的批判 4 Spring包含的模块 5 总结 6 Spring的IoC容器 6 用户注册的例子 7 面向接口编程 8 (用户...
NULL 博文链接:https://bjameng.iteye.com/blog/1468057
Spring的IoC容器之BeanFactory[定义].pdf