Spring AOP:静态代理、动态代理和几种常见的aop配置

JDK动态代理和CGLIB动态代理 在SpringAOP中基于动态代理实现功能的增强,也就是动态的生成代理类,在代理类中织入增强的逻辑然后调用目标对象的方法。动态代理中用的比较多的两种:JDK动态代理、CGLIB动态代理。 JDK动态代理 使用JDK的java.lang.reflect.Proxy类的newProxyInstance方法实现的代理。 用一个测试接口看下具体实现: public interface JdkProxyDemoService { void queryTrs(); } @Service public 阅读详情

本文主要对Spring AOP的相关概念和简单的静态代理、动态代理以及常见的几种AOP配置方式做总结学习。真诚希望大家给予批评和指导。
本文以自己写的一个简单Code为例,主要逻辑结构及说明信息依code中的注释内容为说明,所以可能出现 many codes little explianations.


  1. AOP的常见概念
  2. 静态代理
  3. jdk动态代理
  4. Aspectj and Aspectjweaver
  5. aop-config
  6. CGLIB aop-config
  7. AOP动态代理配置
  8. AOP自动识别动态代理配置

1. AOP常见概念

  • Cross Cutting Concern :
    横切性关注点,补充我们OOP纵向编写的补充,可以理解成遍布在系统的处理流程中的,一种独立的服务。
  • Aspect : 对我们上面的Cross Cutting Concern 的一种模块化,也就是将其封装成一个类。
  • Advice : 对关注点的具体实现,在切面的某个特定的连接点( Joinpoint )上执行的动作。其含有多种通知类型:
    之前、返回之后、抛出之后、环绕通知。具体的可以参考文档。
  • Pointcut : 定义了这个Adivce 应用到那些 Joinpoint 上。
  • Jointpoint : 是 Advice 在应用程序上的执行点或者时机,对Spring来说,它就是方法调用。
  • Weave : 将 Advice 应用到Target Object 上的整个过程叫织入。
  • Target Object : Advice应用的对象。

2. 项目结构

这里写图片描述


3 静态代理和动态代理showing

接口:com.qian.subject.Subject –目标类RealSubject和代理类要实现的接口。
目标类: com.qian.realsubject.RealSubject
静态代理类: com.qian.staticproxy.SubjectStaticProxy
动态代理类: com.qian.dynamicproxy.SubjectDanamicProxy

package com.qian.subject;
/**
 * 实际类RealSubject和代理类要实现的接口;
 * @author Administrator
 */
public interface Subject {

    public void addSub(String name, String password);

    public String findSub(String id);

}
package com.qian.realsubject;
import com.qian.subject.*;

/**
 * Subject的实现类,并重写方法
 * @author Administrator
 *
 */
public class RealSubject implements Subject {

    public void addSub(String name, String password) {
        System.out.println("RealSubject.addSub()   "+ name+"  "+ password);
    }

    public String findSub(String id) {
        System.out.println("RealSubject.findSub()  "+ id);
        return "realSubject.findSub()";
    }

}
package com.qian.staticproxy;

import com.qian.subject.Subject;

public class SubjectStaticProxy implements Subject {
    //Remark: 拿到实际对象的引用;
    private Subject realSubject;

    //这里我们通过构造函数拿到;
    public SubjectStaticProxy(Subject realSubject){
        this.realSubject = realSubject;
    }
    public void addSub(String name, String password) {
        System.out.println("staticProxy do something before realSubject.add()");
        //调用实际对象的方法
        realSubject.addSub(name, password);
    }

    public String findSub(String id) {
        System.out.println("staticProxy do something before realSubject.findSub()");
        return realSubject.findSub(id);
    }

}
package com.qian.danamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class SubjectDanamicProxy implements InvocationHandler {

    //实际要传入的realSubject;
    private Object realSubject;

    public Object getSubjectProxy(Object realSubject){
        this.realSubject = realSubject;
        //都是realSubject的;
        Object proxy = Proxy.newProxyInstance(realSubject.getClass().getClassLoader(), 
                realSubject.getClass().getInterfaces(), 
                this);
        //为了看看这个proxy和invoke(proxy)是否一样
        System.out.println("--proxy=Prox.new...() is "+proxy.getClass().getName());
        return proxy;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("--proxy in invoke parameters is "+proxy.getClass().getName());
        checkInfo();
        Object result = method.invoke(realSubject, args);       
        return result;
    }

    private void checkInfo(){
        System.out.println("Doing some checking things before method invocation");
    }
}

4 Spring实现AOP的方式之Aspectj注解

Aspectj类:com.qian.springaopaspectj.CheckInfoAspect
xml文件:applicationContextAspectj.xml

package com.qian.springaopaspectj;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

/**
 * 将 代理类中 都要做得检查操作(横切性关注点模块化)
 * @author Administrator
 *
 */
@Aspect //对横切性关注点的模块化;
public class CheckInfoAspect {

    //定义advice应用到那些连接点上,也就是advice在应用程序上自行的点或者时机
    //poincuName()就是给这个poincut起个名;
    @Pointcut("execution(* add*(..)) || execution(* find*(..))")
    private void poincutName(){}

    //advice也就是关注点的具体实现;before在连接点JointPoint的前面使用
    @Before("poincutName()")
    public void checkInfo(){
        System.out.println("Doing some checking things before method invocation");
    }

}
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-4.3.xsd
     http://www.springframework.org/schema/tx
     http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
     http://www.springframework.org/schema/aop
     http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">


    <!-- 告诉JVM 我们用了aspectj的 annotation -->
    <aop:aspectj-autoproxy></aop:aspectj-autoproxy>

    <bean id="realSubject" class="com.qian.realsubject.RealSubject"/>
    <bean id="checkInfoAspect" class="com.qian.springaopanno.CheckInfoAspect"/>



</beans>

5 Spring实现AOP的方式之aop-config

目标类:com.qian.realsubject.RealSubject
Advice类:com.qian.springaopxml.CheckInfoAspectXml
xml文件: applicationContextConfig.xml

package com.qian.springaopxml;

/**
 * 模拟将遍布在系统流程中的检查信息(关注点)模块化成一个Aspect
 * @author Administrator
 *
 */
public class CheckInfoAspectXml {

    public void checkInfo(){
        System.out.println("Doing some checking things before method invocation");
    }
}
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-4.3.xsd
     http://www.springframework.org/schema/tx
     http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
     http://www.springframework.org/schema/aop
     http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">


    <bean id="realSubjectCGLIB" class="com.qian.realsubject.RealSubjectCGLIB"/>

    <bean id="checkInfoAspectXml" class="com.qian.springaopxml.CheckInfoAspectXml"/>

    <aop:config>
        <aop:aspect id="checkInfoAspectXml" ref="checkInfoAspectXml">

            <aop:pointcut expression="execution(* com.qian.realsubject.RealSubjectCGLIB.add*(..))||execution(* find*(..))" id="pointcut"/>

            <aop:before method="checkInfo" pointcut-ref="pointcut"/>

        </aop:aspect>
    </aop:config>


</beans>

6 插曲,当目标类没有继承接口时,我们用CGLIB,并配置aop-config

类:com.qian.realsubject.RealSubjectCGLIB
Advice类:com.qian.springaopxml.CheckInfoAspectXml
xml文件: applicationContextConfigCGLIB.xml

package com.qian.realsubject;

/**
 * 没有实现任何接口,我们用CGLIB来动态代理它
 * @author Administrator
 *
 */
public class RealSubjectCGLIB {

    public void addSub(String name, String password) {
        System.out.println("RealSubject.addSub()   "+ name+"  "+ password);
    }

    public String findSub(String id) {
        System.out.println("RealSubject.findSub()  "+ id);
        return "realSubject.findSub()";
    }

}
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-4.3.xsd
     http://www.springframework.org/schema/tx
     http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
     http://www.springframework.org/schema/aop
     http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">


    <bean id="realSubjectCGLIB" class="com.qian.realsubject.RealSubjectCGLIB"/>

    <bean id="checkInfoAspectXml" class="com.qian.springaopxml.CheckInfoAspectXml"/>

    <aop:config>
        <aop:aspect id="checkInfoAspectXml" ref="checkInfoAspectXml">

            <aop:pointcut expression="execution(* com.qian.realsubject.RealSubjectCGLIB.add*(..))||execution(* find*(..))" id="pointcut"/>

            <aop:before method="checkInfo" pointcut-ref="pointcut"/>

        </aop:aspect>
    </aop:config>


</beans>

7 Spring实现AOP的方式之POJO

目标类 : com.qian.realsubject.RealSubjectBean
Advice类: com.qian.springaopproxy.RealSubjectBeanHelper –实现了接口 AfterReturningAdvice, MethodBeforeAdvice
xml文件:applicationContextProxy.xml

package com.qian.realsubject;

/**
 * 为了说明 CGLIB 和spring 可以在 JDK动态代理和CGLIB切换
 * 定义了一个没有实现任何借口的普通类;
 * @author Administrator
 *
 */
public class RealSubjectBean {

    private String subName;
    private String password;

    public String getSubName() {
        return subName;
    }

    public void setSubName(String subName) {
        this.subName = subName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void addSubBean() {
        System.out.println("RealSubjectBean.addSubBean()   "+ subName+"  "+ password);
    }

    public String findSubBean(String subName) {
        System.out.println("RealSubjectBean.findSubBean()  "+ subName);
        return "realSubjectBean.findSubBean()";
    }

}
package com.qian.springaopproxy;

import java.lang.reflect.Method;

import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;

/**
 * 使用spring 典型的动态代理来处理
 * @author Administrator
 *
 */
public class RealSubjectHelper implements AfterReturningAdvice, MethodBeforeAdvice {

    public void before(Method arg0, Object[] arg1, Object arg2) throws Throwable {
        System.out.println(" RealSubjectHelper BeforMehtod: checking information");
    }

    public void afterReturning(Object arg0, Method arg1, Object[] arg2, Object arg3) throws Throwable {
        System.out.println(" RealSubjectHelper AfterMehtod: checking information");
    }

}
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-4.3.xsd
     http://www.springframework.org/schema/tx
     http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
     http://www.springframework.org/schema/aop
     http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">

    <!-- (1)  注册Bean RealSubjectBean 和实现了 MethodBeforeAdvice AfterReturningAdvice接口的 RealSubjectHelper-->

    <bean id="realSubjectBean" class="com.qian.realsubject.RealSubjectBean">
        <property name="subName" value="zhangsan"/>
        <property name="password" value="zhangsan123"/>
    </bean>

    <bean id="realSubjectHelper" class="com.qian.springaopproxy.RealSubjectHelper"/>


    <!-- (2) 使用正则表达式来表示切点Pointcut 使用类 JdkRegexpMethodPointcut-->

    <bean id="pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut">
        <property name="pattern" value=".*find.*"/>
    </bean>


    <!-- (3) 将横切点的具体实现 Advice 和  切点 Pointcut 联合起来 使用类 DefaultPointcutAdvisor-->
    <!--  
    <bean id="pointcutAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
        <property name="pointcut" ref="pointcut"/>
        <property name="advice" ref="realSubjectHelper"/>
    </bean>
    -->
    <bean id="pointcutAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
        <constructor-arg name="pointcut" ref="pointcut"/>
        <constructor-arg name="advice" ref="realSubjectHelper"/>
    </bean>


    <!--  (4) 生成目标对象RealSubjectBean的代理对象 使用类  ProxyFactoryBean -->

    <bean id="realSubjectBeanProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
        <!-- 目标对象 target -->
        <property name="target" ref="realSubjectBean"/>
        <!-- 拦截方法 -->
        <property name="interceptorNames">
            <list>
                <value>pointcutAdvisor</value>
            </list>
        </property>
    </bean>


</beans>

对 7中的xml进行简化

xml文件: applicationContextProxyV2.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-4.3.xsd
     http://www.springframework.org/schema/tx
     http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
     http://www.springframework.org/schema/aop
     http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">

    <!-- (1)  注册Bean RealSubjectBean 和实现了 MethodBeforeAdvice AfterReturningAdvice接口的 RealSubjectHelper-->

    <bean id="realSubjectBean" class="com.qian.realsubject.RealSubjectBean">
        <property name="subName" value="zhangsan"/>
        <property name="password" value="zhangsan123"/>
    </bean>

    <bean id="realSubjectHelper" class="com.qian.springaopproxy.RealSubjectHelper"/>


    <!-- (2) 使用正则表达式来表示切点Pointcut 和 横切点的具体实现Advice自动联合 使用类 RegexpMethodPointcutAdvisor-->

    <bean id="pointcutAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
        <property name="pattern" value=".*find.*"/>
        <property name="advice" ref="realSubjectHelper"/>
    </bean>


    <!--  (3) 生成目标对象RealSubjectBean的代理对象 使用类自动代理生成器 DefaultAdvisorAutoProxyCreator-->

    <bean id="realSubjectBeanProxy" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>

</beans>

8 最主要的Client类

package com.qian.client;

import com.qian.realsubject.RealSubject;
import com.qian.realsubject.RealSubjectBean;
import com.qian.realsubject.RealSubjectCGLIB;
import com.qian.staticproxy.SubjectStaticProxy;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.qian.danamicproxy.SubjectDanamicProxy;
import com.qian.subject.Subject;

/**
 * Client主测试类
 * @author Administrator
 *
 */
public class Client {

    //最通俗易懂的办法 但是耦合度太高了
    public static void subjectImpl(){
        Subject subject = new RealSubject();
        subject.addSub("qian", "520");
        subject.findSub("511");
    }

    // 静态代理
    public static void staticProxy(){

        Subject subject = new SubjectStaticProxy(new RealSubject());
        subject.addSub("name", "password");
        subject.findSub("123");
    }

    // 动态代理
    public static void dynamicProxy(){

        Object proxy = new SubjectDanamicProxy().getSubjectProxy(new RealSubject());
        Subject subject = (Subject)proxy;
        subject.addSub("zhangsan", "pass123");
        subject.findSub("134");
    }

    //使用 Aspectj.jar 和Aspectjweaver.jar 进行注释 推崇
    public static void springaopAspectj(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContextAspectj.xml");
        Subject subject = (Subject) context.getBean("realSubject");
        subject.addSub("spring", "aop");
        subject.findSub("1231");
    }

    //使用spring的aop-config进行配置、推崇
    public static void springaopConfig(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContextConfig.xml");
        Subject subject = (Subject) context.getBean("realSubject");
        subject.addSub("spring", "aop");
        subject.findSub("1231");
    }

    //对没有实现接口的类使用CGLIB 并使用spring的aop-config进行配置
    public static void springaopConfigCGLIB(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContextAopConfigCGLIB.xml");
        RealSubjectCGLIB subject = (RealSubjectCGLIB) context.getBean("realSubjectCGLIB");
        subject.addSub("spring", "aop");
        subject.findSub("1231");
    }

    //spring AOP动态代理
    public static void springaopProxy(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContextProxy.xml");
        RealSubjectBean subjectBean = (RealSubjectBean) context.getBean("realSubjectBeanProxy");
        subjectBean.addSubBean();
        subjectBean.findSubBean("springaop4");
    }

    //spirng AOP自动进行匹配的动态代理
    public static void springaopProxyV2(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContextProxyV2.xml");
        RealSubjectBean subjectBean = (RealSubjectBean) context.getBean("realSubjectBean");
        subjectBean.addSubBean();
        subjectBean.findSubBean("springaop4");
    }
    public static void main(String[] args) {
        //subjectImpl();
        //staticProxy();
        //dynamicProxy();
        //springaopConfig();
        //springaopConfigCGLIB();
        //springaopProxy();
        //springaopProxyV2();
    }

}

结果都是预期的结果这里就不显示了。


本project使用的是Maven建的、所以pom.xml如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>springaop</groupId>
  <artifactId>SpringAop</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.3.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.3.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>4.3.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>4.3.0.RELEASE</version>
    </dependency>

    <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.8.5</version>
    </dependency>

    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.8.5</version>
    </dependency>

    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>3.2.0</version>
    </dependency>

  </dependencies>
</project>

如果有想找完整版的src文件的朋友,可以留邮箱、


Thank you for your consideration. Thanks everyone. And I am grateful to those who give any comments or suggestions in the futrue.

【Spring】Spring第二天 - AOP 详解、动态代理设计模式(JDK和cglib) 一.AOP 1.AOP:中文名称面向切面编程 2.英文名称:(Aspect Oriented Programming) 3.正常程序执行流程都是纵向执行流程 3.1 又叫面向切面编程,在原有纵向执行流程中添加横切面 3.2 不需要修改原有程序代码 3.2.1 高扩展性 3.2.2 原有功能相当于释放了部分逻辑.让职责更加明确. 4.面向切面编程是什么? 4.1 在程序原有纵向执行流程中,针对某一... 阅读详情

相关推荐

python毕设 基于Web的中药材信息查询系统程序+论文

***(程序+源码+数据库+调试部署+开发环境)论文文档1,文末可获取,系统界面在最后面。****

m0_74825541的博客 1263

Spring Boot 自动配置 : AopAutoConfiguration & 源码解析

https://www.jianshu.com/p/484bae9d1fb2 概述 自动配置AopAutoConfiguration类的主要任务是根据配置参数使用注解@EnableAspectJAutoProxy。 该自动配置类通过注解声明了自己生效的条件是 : 以下类必须存在于classpath : EnableAspectJAutoProxy Aspect Advice An...

z69183787的专栏 2271

从CMOS到CML:手把手教你为PLL选对分频器电路(附性能对比与选型指南)

本文深入解析了PLL分频器电路的三大主流架构——静态CMOS、动态TSPC和CML,通过性能参数对比和实测数据,提供了从频率需求、功耗预算到噪声防护的完整选型指南。特别针对高频应用的CML分频器设计要点和混合架构优化方案,为射频与模拟IC设计工程师提供实用参考。

weixin_30887919的博客 466

spring-aop与auto

/ @Autowired自动装配原理:首先会根据byType方式,进行自动装配,如果能唯一匹配,直接执行自动装配,如果不能唯一匹配(存在同类型多个实例对象),会再次尝试使用byName方式,根据当前实体属性名,到容器中进行匹配(容器中bean的id值),如果能唯一匹配,仍会执行自动装配,如果匹配失败,直接抛出异常。根据实例属性的类型,到容器中,根据类型进行唯一匹配,如果可以匹配到对应类型的bean的实例,就会执行自动装配,如果不能唯一匹配(同类型的bean有多个),会报错,并装配失败。...

hshshshh的博客 436

CLion for Mac(m1)配置GCC编译器

条件:电脑已经下载过XCode 一. 下载HomeBrew homebrew是一款macos,linux下的包管理工具,我们需要使用他来下载GCC 下载方法: 1.打开终端(terminal) 2.输入 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ps.有可能会遇到的问题 我当初下载挂了VPN,CSDN上还有很多解决问题的方法,可以将错误信

supermario19的博客 7856

保姆级教程:用STM32F103C8T6和MAX6675搞定K型热电偶测温(附模拟/硬件SPI双版本代码)

本文提供STM32F103C8T6与MAX6675实现K型热电偶高精度测温的保姆级教程,涵盖硬件连接、SPI驱动实现及模拟SPI方案,并附双版本代码。详细解析温度数据读取、处理及常见问题排查,助力工业控制、实验室设备等场景的稳定测温系统搭建。

weixin_30765505的博客 594

Spring的AOP原理

Spring的AOP是我们在开发中比较常用的一种思想,比如日志的数据等,那Spring是如何通过配置来创建AOP的呢 本文主要通过注解配置来讲解 解析切面类 我们在使用注解配置AOP的时候通常需要@EnableAspectJAutoProxy这个注解来开启AOP 那其实这个注解里的@Import注解里有个AspectJAutoProxyRegistrar类来注册对应的BeanDefinition 这个类里注册了一个AnnotationAwareAspectJAutoProxyCreator这个Bea

小年的博客 703

一篇文章带你搞定数学建模里的主成分分析(05年水质问题示例应用讲解含代码)

文章目录一、题目分析二、原理公式三、MATLAB实现某一地区的主成分分析四、MATLAB 实现所有地区28个月的综合分析五、注意 一、题目分析 对长江近两年多的水质情况做出定量的综合评价,并分析各地区水质的污染状况 考虑到各指标之间可能存在一定的相关性,选用主成分分析法对长江流域主要城市水质检测报告进行分析,选取主成分,并把主成分得分按照方差贡献率加权求和,得到每个地区的污染综合评价指数,进而可以计算每个月长江流域的污染综合评价指数,对平均综合评价指数进行排序 二、原理公式 根据主成分分析的方法,分析长江沿

南淮北安的博客 2632

使springAOP生效不一定要加@EnableAspectJAutoProxy注解

本文主要分析了在springboot环境下,不加@EnableAspectJAutoProxy注解springAOP仍然生效的问题。为了保险期间请一律加上@EnableAspetJAutoProxy注解。AopAutoConfiguration类等同于@EnableAspectJAutoProxy注解;spring.aop.auto=ture/false属性可以控制AopAutoConfiguration类是否生效;

band_mmbx的博客 949

Linux下使用Nginx搭建Rtmp流媒体服务器,实现视频直播功能

一、环境介绍 操作系统:虚拟机运行的Ubuntu18.04 64位系统 二、流媒体服务器介绍 百度百科: 流媒体指以流方式在网络中传送音频、视频和多媒体文件的媒体形式。相对于下载后观看的网络播放形式而言,流媒体的典型特征是把连续的音频和视频信息压缩后放到网络服务器上,用户边下载边观看,而不必等待整个文件下载完毕。由于流媒体技术的优越性,该技术广泛应用于视频点播、视频会议、远程教育、远程医疗和...

7167

芒果YOLOv8改进160:姿态估计Head篇:即插即用|轻量化非对称多级压缩LOADH旋转检测头,原创改进适配YOLOv8高效检测头,检测头新颖改进,全网首发独一份

芒果YOLOv8改进159:OBB旋转检测头Head篇:即插即用|轻量化非对称多级压缩LOADH旋转检测头,原创改进适配YOLOv8高效检测头,检测头新颖改进,全网首发独一份

包括YOLOv5、YOLOv7、YOLOv8等模型改进 823

​温故知新——Spring AOP

SpringAOP面向切面编程,相信大家都不陌生,它和SpringIOC是Spring赖以成名的两个最基础的功能。在咱们平时的工作中,使用IOC的场景比较多,像咱们平时使用的@Controller、@Service、@Repository、@Component、@Autowired等,这些都和IOC相关。...

wuxiaopengnihao1的博客 313

猿创征文|Qt 文件和目录应用讲解【QCoreApplication】【QFile、QFileInfo】【QTemporaryDir和QTemporaryFile】【QDir】【QFileSyste】

Qt 文件和目录精准讲解【QCoreApplication】【QFile、QFileInfo】【QTemporaryDir和QTemporaryFile】【QDir】【QFileSyste】【QFileDialog】 第一章 QCoreApplication类 第一节 QCoreApplication常用函数方法 第二节 QCoreApplication举例 第二章 QFile类 第一节 静态函数方法 第二节 成员函数方法 第三章 QFileInfo类 第一节 常用函数方法 第四章 QDir类

Qt历险记,专注Qt技术,三年医疗设备研发经验,1年机器视觉研发经验,半年柔性传感研发经验。 950

Spring全家桶面试题(一)之Spring Framework(六)

AOP(Aspect-Oriented Programming),一般称为面向切面编程,用于将那些与业务无关,但却对多个对象产生影响的公共行为和逻辑,抽取并封装为一个可重用的模块,这个模块被命名为“切面”(Aspect),减少系统中的重复代码,降低了模块间的耦合度,同时提高了系统的可维护性。可用于权限认证、日志、事务处理等。AOP、OOP在字面上虽然非常类似,但却是面向不同领域的两种设计思想。 **OOP(面向对象编程)**针对业务处理过程的实体及其属性和行为进行抽象封装,以获得更加清晰高效的逻辑单元划分。

TPH_BETTER.的博客 174

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

讲解AOP代理和重点解析Spring AOP代理(动态代理),看完秒懂!!!!

上一章我们生动形象的讲了什么是AOP面向切面编程以及代码示例,有不明白的小伙伴可以去看看(https://blog.csdn.net/qq_32317661/article/details/82878679),承上启下,这一篇讲一下Spring AOP代理的两种方式和它的大致原理。 一、AOP代理 AOP代理主要分为静态代理和动态代理,静态代理的代表为AspectJ;而动态代理则以Spring...

healer的博客 8327

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

【Spring Boot】Spring AOP动态代理,以及静态代理

定义 MethodInterceptor 并重写 intercept 方法, intercept 于增强标方法,和JDK动态代理中的 invoke 方法类似//?标对象, 即被代理对象@Override// 代理增强内容System.out.println("我是中介, 开始代理");//通过反射调?被代理类的方法//代理增强内容System.out.println("我是中介, 代理结束");

2509_92430413的博客 1763

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Spring AOP原理之动态代理

什么是代理? 指为一个目标对象提供一个代理对象, 并由代理对象控制对目标对象的引用. 使用代理对象, 是为了在不修改目标对象的基础上, 增强目标对象的业务逻辑. 静态代理 静态代理的特点是, 为每一个业务增强都提供一个代理类, 由代理类来创建代理对象. 下面我们通过静态代理来实现对转账业务进行身份验证. (1) 转账业务 public interface IAccountService { ...

Tyshawn的博客 5万+

Spring-AOP详解(AOP概念,原理,动态代理,静态代理)

重点:1.Spring-Framework的proxytargetclass默认值为false,所以Spring-Framework,JDK和CGLIB两个代理都使用 2.而Spring-Boot需要区分版本:对于Spring-Boot 2.xxx版本,proxytargetclass默认值也为false.所以,Spring-Boot 2.xxx版本也是JDK和CGLIB两个代理都使用,而Spring-Boot 3.xxx版本proxytargetclass默认值则为true,所以Spring-Boot 3

robin_suli的博客 1805

【Spring-AOP基础】深入浅出Spring-AOP(从动态代理到Spring AOP)

AOP(Aspect Oriented Programming) 1.概念 AOP:全称是 Aspect Oriented Programming即:面向切面编程。

ATFWUS的博客 11万+

静态代理、动态代理、spring动态代理(Spring AOP面向切面编程)、spring动态代理注解版

目录 静态代理 列:实现静态代理 代理接口User.java 目标对象 实际业务逻辑实现方法UserImpl.java 代理类UserProxy.java 测试 动态代理 列: 实现动态代理 创建po对象 创建dao 创建代理类MyProxy.java 测试 Spring Aop 面向切面编程(spring动态代理) 列:aop练习 导包 User.java ...

Birdlun的博客 2656

JavaEE进阶(11)Spring AOP:AOP概述、Spring AOP快速入门、详解)、原理(代理模式:静态代理、动态代理:JDK动态代理、CGLIB动态代理)、源码剖析(了解)

AOP概述、Spring AOP快速入门、Spring AOP详解(涉及的核心概念、通知类型、多个AOP程序的执行顺序、@PointCut、切面优先级 @Order、切点表达式、自定义注解)、Spring AOP原理(代理模式——静态代理 、动态代理:JDK动态代理、CGLIB动态代理)、Spring AOP源码剖析(了解)

m0_74343467的博客 1567

Spring动态代理的两种区别

Spring的面向切面编程也是基于动态代理来实现的 静态代理:也就是自己手动创建的代理对象 动态代理:也就是在程序运行中通过配置参生的 那么Spring的AOP也就是面向切面编程,就是基于动态代理来实现的,通过代理原始类增加额外功能,我们可以将额外功能一次定义然后配合切点达到多次使用的效果,比如 做日志啊 事物啊 时间啊等等…提高了复用性 开发效率. 那么在Spirng当中动态代理有两种 ...

qq_42807370的博客 1万+

Spring AOP与静态代理/动态代理

在梳理Aop的原理之前,我们先了解一下代理模式,其中分静态代理与动态代理。例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。提示:以下是本篇文章正文内容,下面案例可供参考我们一开始简单的初步认识了下代理模式,其中常见的实现方式有静态代理与动态代理,同时写了打印机🖨️的调用时机代码。接着我们思考🤔代理模式和我们使用spring aop有什么联系?简单的了解aop 与spring aop的实现方式。

Bruce__taotao的博客 2079

别再说 Spring AOP 默认用的是 JDK 动态代理

话不多说,发车! 说下 AOP AOP,Aspect Oriented Programming,面向切面编程。 将一些通用的逻辑集中实现,然后通过 AOP 进行逻辑的切入,减少了零散的碎片化代码,提高了系统的可维护性。 具体是含义可以理解为:通过代理的方式,在调用想要的对象方法时候,进行拦截处理,执行切入的逻辑,然后再调用真正的方法实现。 例如,你实现了一个 A 对象,里面有 addUser 方法,此时你需要记录该方法的调用次数。 那么你就可以搞个代理对象,这个代理对象也提供了 addUser.

HongYu012的博客 3569

JDK动态代理、Cglib动态代理及Spring AOP

Java中的JDK动态代理是一种通过反射机制生成代理对象的技术,使得我们能够在运行时动态地创建某个接口的代理类,而无需手动编写实现类。JDK动态代理通常用于横切关注点(如日志、事务管理、安全性等)在方法调用前后进行处理,而不需要修改目标类的源代码。JDK 动态代理特点只能代理实现了接口的类或对象。在运行时动态生成代理类,避免了手动创建静态代理类的繁琐。使用简单,适用于代理接口的场景。应用场景:适合需要对接口进行动态代理的场景,如一些简单的业务逻辑。Cglib 动态代理特点。

m0_67391870的博客 1126
上一篇: 初识 Maven
下一篇: Hibernate: 三种状态和CRUD四种操作
Coder-Qian
博客等级 码龄11年 63粉丝 73原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址