SSM-Spring-14:Spring中默认自动代理DefaultAdvisorAutoProxyCreator

SSM-Spring-14:Spring中默认自动代理DefaultAdvisorAutoProxyCreator

大家好,又见面了,我是全栈君。

 

 

------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥-------------

 

 

默认自动代理DefaultAdvisorAutoProxyCreator

本处没有什么要讲的,放原代码

  ISomeService接口:

 

package cn.dawn.day17atuo01;

/**
 * Created by Dawn on 2018/3/8.
 */
public interface ISomeService {
    public void insert();
    public void delete();
    public void select();
    public void update();
}

 

  SomeServiceImpl类继承上面的那个接口:

 

package cn.dawn.day17atuo01;


/**
 * Created by Dawn on 2018/3/8.
 */
public class SomeServiceImpl implements ISomeService{

    public void insert() {
        System.out.println("insert ok");
    }

    public void delete() {
        System.out.println("delete ok");

    }

    public void select() {
        System.out.println("select ok");

    }

    public void update() {
        System.out.println("update ok");

    }
}

 

  LoggerBefore类,做了前置增强

 

package cn.dawn.day17atuo01;


import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;

/**
 * Created by Dawn on 2018/3/5.
 */
/*前置增强*/
public class LoggerBefore implements MethodBeforeAdvice {
    public void before(Method method, Object[] objects, Object o) throws Throwable {
        System.out.println("日志记录");
    }
}

 

  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:aop="http://www.springframework.org/schema/aop"
       xmlns:p="http://www.springframework.org/schema/p" 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/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <!--要增强的对象-->
    <bean id="service" class="cn.dawn.day17atuo01.SomeServiceImpl"></bean>
    <!--增强的内容-->
    <bean id="myadvice" class="cn.dawn.day17atuo01.LoggerBefore"></bean>
    <!--顾问-->
    <bean id="myadvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
        <property name="advice" ref="myadvice"></property>
        <!--<property name="mappedNames" value="do*"></property>-->
        <!--<property name="pattern" value=".*do.*"></property>-->
        <property name="patterns" value=".*select.*"></property>
    </bean>
    <!--默认自动代理-->
    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"></bean>

</beans>

 

  必须要有顾问,没有不可以,默认自动代理里面不用实现参数,他自动匹配

 

  单测方法:

 

package cn.dawn.day17auto01;


import cn.dawn.day17atuo01.ISomeService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by Dawn on 2018/3/3.
 */
public class test20180312 {
    @Test
    /*默认自动代理*/
    public void t01(){
        ApplicationContext context=new ClassPathXmlApplicationContext("ApplicationContext-day17auto01.xml");
        ISomeService service = (ISomeService) context.getBean("service");

        service.select();

    }
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/107657.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • python打包小程序[通俗易懂]

    概述pyinstaller是一个十分有用的第三方库,能够在Windows,Linux、MacOSX等操作系统下将Python源文件打包。通过打包可以在没有Python的环境中运行。pipinstaller需要在命令行用pip3安装pip3installpyinstallerpyinstaller库会自动将pyinstaller命令安装到Python解释器目录中,与pip3的命令路…

    2022年4月13日
    34
  • shell中的while循环实例[通俗易懂]

    shell中的while循环实例[通俗易懂]1.利用while循环计算1到100的和:示例代码1:#!/bin/bashi=1sum=0while[$i-le100]do letsum=sum+$i leti++doneecho$sum示例代码2:利用while循环计算1到100之间所有奇数之和#!/bin/bashi=1sum=0while[$i-le100]do letsum=sum+$i leti…

    2022年7月24日
    10
  • Java基础篇:多重继承的实现

    Java基础篇:多重继承的实现

    2021年10月4日
    141
  • FPGA和CPLD对比与入门

    FPGA和CPLD对比与入门入门介绍:1、EMP240使用很广泛了,8元一片。EMP240顾名思义具有240个宏单元,或者说240个触发器,或者理解成240个bit的存储单元。2、仿真分2步,写逻辑时用QUARTUS自带的仿真;逻辑写完后,最好用modelsim专门仿真。3、如果你需要100个逻辑单元,实际用的可能是120个,因此要留出20%的余量。4、一个小技巧,针对EPM240和570来说,常用的封装T

    2022年6月4日
    45
  • 中介效应分析与路径分析的区别_完全中介效应

    中介效应分析与路径分析的区别_完全中介效应这篇文章主要是介绍中介效应分析及路径分析的概念,以及操作步骤,注意事项。好多内容就是拷贝的邱皓政老师的《量化研究与统计分析:SPSS(PASW)数据分析范例解析》第12章节,然后在中间加入了少部分自己看的过程的一些理解吧。1.中介效应分析从上述的阐述可以知道,中介效应分析其实就是有一个变量充当了中介变量,X->Y是通过中介变量Z来传递影响的。如果是完全中介效应就是完全由Z来传递影…

    2022年8月24日
    5
  • SPSSlogistic回归分析_logistic回归分析表格解读

    SPSSlogistic回归分析_logistic回归分析表格解读spsslogistic回归分析结果如何分析如何用spss17.0进行二元和多元logistic回归分析一、二元logistic回归分析二元logistic回归分析的前提为因变量是可以转化为0、1的二

    2022年8月2日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号