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

Spring实战第一章

2018-03-22 08:58 141 查看

Spring之旅

1.1 简化Java开发

为了降低Java开发的复杂性,Spring采取了以下4中策略:

+ 基于POJO的轻量级和最小侵入性编程

+ 通过依赖注入和面向接口实现松耦合

+ 基于切面和惯例进行声明式编程

+ 通过切面和模板减少样板式代码

1.2 容纳你的bean

Spring并不是只有一个。Spring自带多个容器实现,可以归为两种不同类型:

+ bean工厂

+ 应用上下文(由org.springframework.context.ApplicationContext接口定义),基于BeanFactory创建

1.2.1 使用应用上下文

AnnotationConfigApplicationContext从一个或多个基于java的配置类中加载Spring应用上下文

AnnotationConfigWebApplicationContext从一个或多个基于java的配置类中加载Spring Web应用上下文

ClassPathXmlApplicationContext从类路径下的一个或多个XML配置文件中加载上下文定义,把应用上下文的定义文件作为类资源

FileSystemXmlapplicationContext从文件系统下的一个或多个XML配置文件中加载上下文定义

XmlWebApplicationContext从Web应用下的一个或多个XML配置文件中加载上下文定义

ApplicationContext context = new AnnotationConfigApplicationContext(com.springinaction.knights.config.KnightConfig.class);


ApplicationContext context = new FileSystemXmlapplicationContext("c:/knight.xml");


ApplicationContext context = new ClassPathXmlApplicationContext("knight.xml");


另外两种的详细讨论请见第8章

1.2.2 bean的生命周期

Spring对bean进行实例化

Spring将值和bean的引用注入到bean对应的属性中

如果bean实现了BeanNameAware接口,Spring将bean的ID传递给setBeanName()方法

如果bean实现了BeanFactoryAware接口,Spring将调用setBeanFactory()方法,将BeanFactory容器实例传入

。。。

俯瞰Spring风景线

Spring模块

Spring核心容器

Spring的AOP模块

数据访问与集成

Web与远程调用

Instrumentation

测试

Spring Portfolio

Spring Web Flow

Spring Web Service

Spring Security

Spring Integration
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Spring实战