1、Spring
Core Container(核心容器)
主要有:Beans模块、Core模块、Context模块、Context-support模块、SpEL模块
·Beans模块:提供了BeanFactory,是工厂模式的经典实现,Spring将管理对象称为Bean。
·Core核心模块:提供了Spring框架的基本组成部分,包括IoC和DI功能。
·Context上下文模块:建立在Core和Beans模块的基础之上,它是访问定义和配置的任何对象的媒介。其中ApplicationContext接口是上下文模块的焦点。
·Context-support 模块:第三方库的集成支持,比如缓存(EhCache、Guava、JCache)、邮件服务(JavaMail)、任务调度(CommonJ、Quartz)和模板引擎(FreeMarker、JasperReports、速率)。
·SpEL模块:它提供了Spring Expression Language支持,是运行时查询和操作对象图的强大的表达式语言。
Data Access/Integeration(数据访问/集成)
主要有:JDBC模块、ORM模块、OXM模块、JMS模块、Transactions事务模块
Web
主要有:WebSocket模块、Servlet模块、Web模块、Portlet模块
·WebSocket模块:它提供了WebSocket 和SockJS的实现,以及对STOMP的支持。
·Servlet(Spring-webmvc)模块:包含了Spring的模型—视图—控制器(MVC)和REST Web Services实现的Web应用程序。
·Web模块:提供了基本的Web开发集成特性,例如:多文件上传功能、使用Servlet监听器来初始化IoC容器以及Web应用上下文。
·Portlet模块:提供了在Portlet环境中使用MVC实现,类似Servlet模块的功能。
其他模块
主要有:AOP、Aspects、Instrumentation、Messaging、Test
Spring的4个基础 jar 包:
·spring-core-4.3.6.RELEASE.jar:包含Spring框架基本的核心工具类,Spring其他组件都要用到这个包里的类,是其他组件的基本核心。
·spring-beans-4.3.6.RELEASE.jar:所有应用都要用到的JAR包,它包含访问配置文件、创建和管理Bean以及进行Inversion of Control(IoC)或者Dependency Injection(DI)操作相关的所有类。
·spring-context-4.3.6.RELEASE.jar:Spring提供了在基础IoC功能上的扩展服务,还提供了许多企业级服务的支持,如邮件服务、任务调度、JNDI定位、EJB集成、远程访问、缓存以及各种视图层框架的封装等。
·spring-expression-4.3.6.RELEASE.jar:定义了Spring的表达式语言。
第三方依赖包:commons-logging1.2.jar
Spring 核心容器
Spring 提供了两种核心容器:BeanFactory、ApplicationContext
BeanFactory:由org.springframework.beans.facytory.BeanFactroy接口定义,是基础类型的IOC容器。负责初始化Bean和调用它们的生命周期方法。常用实现:org.springframework.beans.factory.xml.XmlBeanFactory。语法如下:
BeanFactory beanFactory = new XmlBeanFactory(new FileSystemResource("F:/applicationContext.xml"));
ApplicationContext:创建实例的两种方法:
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(String configLocation);
注:applicationContext.xml
ApplicationContext applicationContext = new FlieSystemXmlApplicationContext(String configLocation);
注:D:/workspaces/applicationContext.xml
实例化ApplicationContext容器:
在Java项目中,采用ClassPathXMLApplicationContext类来实例化ApplicationContext容器;
在web项目中,实例化工作由web服务器来完成。web服务器实例化ApplicationContext容器,基于ContextLoaderListener实现,此方法需在web.xml中配置:
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- Spring将加载 spring目录下的applicationContext.xml文件 -->
<param-value>classpath:spring/applicationContext.xml</param-value>
</context-param>
<!-- 指定以ContextLoaderListener方式启动Spring容器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Spring入门程序
1、新建Web项目,将4个基础包和commons-logging包复制到lib下
2、新建com.kdd.ioc包、UserDao类、say()方法
3、在src目录下,新建applicationContext.xml,并配置Bean
4、创建测试类,TestIoc
注:applicationContext.xml中约束配置,docs->spring-framework-reference->html->index.html->Overview of Spring Framework->Configuration metadata
版本号信息:http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
概念:
依赖注入:Spring容器负责,将依赖对象赋值给调用者
依赖注入方式:setter方式注入;构造方法注入;
控制反转:对象的实例创建由调用方,反转到了Spring容器
AOP:对oop的完善,oop负责程序的上下顺序,aop负责程序的左右顺序
setter方式注入程序
构造方法注入程序
Bean