Spring--IOC--AOP

Spring structure:

 

 ===============================================IOC===============================================

 IOC container is the core Spring Framework, Spring Beans management of the entire life cycle (from creation to destruction), mainly consists of two different types of containers. BeanFactory ApplicationContext container including a container all the features:

1, Spring BeanFactory container

2、Spring ApplicationContext 容器

 

bean property assignment mode :

  Index can be specified as a parameter, heavier loads can be specified parameter types: by constructors

  By property

  Through p namespace:

    a, p import namespace

    b, it is written with a prefix tag / properties

    

 

 

 

bean Object Scope:

  

 

 

 

Examples of static factory and factory:

  

 

 

 

 

 

 

 bean post-processors, regardless of whether the bean initialization method, the post-processor will have its default, will continue to work:

public class InitHelloWorld implements BeanPostProcessor{
    public Object postProcessBeforeInitialization(Object bean,String beanName) {
        System.out.println("BeforeInitialization:"+beanName);
        return bean;  // you can return any other object as well
    }
    
    public Object postProcessAfterInitialization(Object bean,String beanName) {
        System.out.println("AfterInitialization:"+beanName);
        return bean;  // you can return any other object as well
    }
}

spring管理连接池:

 

 

 

            

从配置文件中读取配置:

获取连接:

 

 

 

   

 

自动装配:

 

 自动扫描:

 

 

 

 

 @Autowired注解实现类型自动装配:

  1. 找到一个就装配,没有找到抛出异常,可以指定@Autowired(required=false)没有找到赋为null
  2. 当有个多个时(继承关系)按照变量名作为id继续匹(通常情况下不让spring使用变量名,使用@Qualifier("指定名称")),如果没有匹配上抛异常
  3. 方法上加注解

  4.@Autowired和@Resource的区别

 

 Spring单元测试:

 

 

 泛型依赖注入:

 

 ============================================AOP============================================

 

 

 

 AOP专业术语:

 

 

 

 

 使用步骤:

1、导入包

 

 

2、添加注解配置,告诉spring哪个是切面类

3、告诉spring切面类中每个方法都是何时何地运行

     切入点表达式:

    

 

 

4、 开启基于注解的AOP功能

基于xml配置AOP:

 

 

 

 

切入点表达式重用:

 

 

 环绕通知:

 

 

 

 

 

 

 

实现AOP的两种动态代理模式:

面向接口(MyMathCalculator implements Calculator)时,是jdk帮我们创建的代理:

 

 

 

   如果没有接口时,cglib帮我们创建代理:

  

 AOP使用场景:

  

 ApplicationContext和BeanFactory的区别:

 

 

 

 

https://www.w3cschool.cn/wkspring/dcu91icn.html

Guess you like

Origin www.cnblogs.com/tianboblog/p/12334607.html