Spring简单介绍
来源:互联网 发布:博彦科技北京java面试 编辑:程序博客网 时间:2024/06/03 19:55
Spring:
IOC:
控制反转. -> 对象由容器创建的过程.
DI:
依赖注入. -> 由容器在程序运行的过程动态的注入依赖的对象的过程.
AOP:
面向切面编程 -> 将程序当中的关注点(日志,权限,加密,解密,校验)通用功能,以模块的形式加 横向增强 入到原程序中的某个过程,
OOP:
继承 纵向增强
-> 通过配置文件来读取类的定义,反射创建对象,存到一个map, 要用的时候取出来.
AOP: 动态代理
采用两种机制: 面向接口的jdk动态代理(默认)
面向继承的cglib的动态代理
AspectJ的动态代理框架
AOP 术语:
目标类:
代理类:
增强:
前置、后置、环绕、返回值后的、抛出异常的
切入点:
可以加入增强的位置 =》切入点表达式
联接点:
加入增强的位置
织入:
1、基于注解的配置
a、写一个切面类
b、在beans.xml中加入注解框架配置 引入aop命名空间
<aop:aspectJ /> ->通知到spring框架 要使用aspectJ的注解解析框架
c、在切面类上加入
@Component
@Aspect
d、在切面类中加入一个切入点,用于写切入点表达式
@Pointcut(切入点表达式)
private void xxx(){};
e、配置增强类型
@Before(切入点表达式)
public void log(){};
2、基于XML的配置
===========================================================================================
1. spring的配置:
<bean id="" class="" >
<property name="" value="">
<property name="" ref="">
2. spring创建一个bean的方式.
a. 通过构造器
b. 通过静态工厂
c. 通过实例工厂.
3. DI的方式:
a. 通过构造方法
b. 通过set方法
4. bean的生命周期:
init-method="" destroy-method=""
5. bean的作用域 scope:
scope="singleton" -> 单例
scope="prototype"
6. DI的参数的类型:
a. 基本类型 value
b. 引用类型 ref
c.集合类型
list
<list>
set
map
property
7. 装配的方式:
<bean autowired="byName/byType" >
小结: <bean id="" class="" init-method="" destroy-method="" scope="" autowired="">
<property name="" value="">
<property name="" ref="">
<property name="">
<list>
<set>
<peroperties>
===========================================================================
xml-based
annotation
1. context命名空间,引用context
2. 加入注解的配置
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/> 加入注解解析框架.
<context:component-scan base-package="包路径"/>
</beans>
-> spring注解解析框架支持的注解:
加在类定义上的: -> IOC
@Component 通用注解
@Repository("名字/spring的bean的id")
@Service
@Controller
-> spring支持的di注解
@Required
@Autowired
@Qualified(name="要注入的bean的id名")
@Resource(name="要注入的bean的id名")
-> spring的bean 的生命周期控制
@PostConstruct -> init-method
@PreDestroy -> destroy-method
IOC:
控制反转. -> 对象由容器创建的过程.
DI:
依赖注入. -> 由容器在程序运行的过程动态的注入依赖的对象的过程.
AOP:
面向切面编程 -> 将程序当中的关注点(日志,权限,加密,解密,校验)通用功能,以模块的形式加 横向增强 入到原程序中的某个过程,
OOP:
继承 纵向增强
-> 通过配置文件来读取类的定义,反射创建对象,存到一个map, 要用的时候取出来.
AOP: 动态代理
采用两种机制: 面向接口的jdk动态代理(默认)
面向继承的cglib的动态代理
AspectJ的动态代理框架
AOP 术语:
目标类:
代理类:
增强:
前置、后置、环绕、返回值后的、抛出异常的
切入点:
可以加入增强的位置 =》切入点表达式
联接点:
加入增强的位置
织入:
加入增强的过程
1、基于注解的配置
a、写一个切面类
b、在beans.xml中加入注解框架配置 引入aop命名空间
<aop:aspectJ /> ->通知到spring框架 要使用aspectJ的注解解析框架
c、在切面类上加入
@Component
@Aspect
d、在切面类中加入一个切入点,用于写切入点表达式
@Pointcut(切入点表达式)
private void xxx(){};
e、配置增强类型
@Before(切入点表达式)
public void log(){};
2、基于XML的配置
===========================================================================================
1. spring的配置:
<bean id="" class="" >
<property name="" value="">
<property name="" ref="">
2. spring创建一个bean的方式.
a. 通过构造器
b. 通过静态工厂
c. 通过实例工厂.
3. DI的方式:
a. 通过构造方法
b. 通过set方法
4. bean的生命周期:
init-method="" destroy-method=""
5. bean的作用域 scope:
scope="singleton" -> 单例
scope="prototype"
6. DI的参数的类型:
a. 基本类型 value
b. 引用类型 ref
c.集合类型
list
<list>
set
map
property
7. 装配的方式:
<bean autowired="byName/byType" >
小结: <bean id="" class="" init-method="" destroy-method="" scope="" autowired="">
<property name="" value="">
<property name="" ref="">
<property name="">
<list>
<set>
<peroperties>
===========================================================================
xml-based
annotation
1. context命名空间,引用context
2. 加入注解的配置
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/> 加入注解解析框架.
<context:component-scan base-package="包路径"/>
</beans>
-> spring注解解析框架支持的注解:
加在类定义上的: -> IOC
@Component 通用注解
@Repository("名字/spring的bean的id")
@Service
@Controller
-> spring支持的di注解
@Required
@Autowired
@Qualified(name="要注入的bean的id名")
@Resource(name="要注入的bean的id名")
-> spring的bean 的生命周期控制
@PostConstruct -> init-method
@PreDestroy -> destroy-method
0 0
- Spring 简单介绍
- Spring Batch 简单介绍
- 简单介绍Spring Timer
- spring surf 简单介绍
- spring简单介绍
- Spring MVC 简单介绍
- Spring MVC简单介绍
- spring aop 简单介绍
- Spring 简单的介绍
- Spring简单介绍
- spring定时器简单介绍
- Spring Boot简单介绍
- spring 体系结构简单介绍
- Spring Cloud简单介绍
- Spring简单介绍
- spring cloud 简单介绍
- Spring 简单介绍
- Spring 简单介绍 Spring 注入
- Bootstrap的js插件之轮播(carousel)
- Linux下如何查看系统启动时间和运行时间
- Valgrind简单用法
- F808尝试写随笔:java.lang.ClassNotFoundException:StrutsPrepareAndExecuteFilter
- poj3614 优先队列
- Spring简单介绍
- adb install将app安装到eclipse Android sdk 模拟器上看效果
- 编译器编译优化---常量传播和常量折叠
- git
- PHP 数据库读写分离的经典例子
- EDK2 环境搭建 & Shell - Debug (cmd)
- 16位2进制补码转换为10进制
- 9 个最佳的 Sublime Text 3主题
- python开发--random