欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Spring基于advisor配置aop過(guò)程解析

 更新時(shí)間:2020年10月26日 14:26:52   作者:Y_wee  
這篇文章主要介紹了Spring基于advisor配置aop過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

1、目標(biāo)類

package com.gec.target;

public class Hadoop { 
  public void eatting() {
    System.out.println("大象正在吃東西 1"); 
    try {
      //耗時(shí)5秒 
      Thread.sleep(5000); 
    } catch (InterruptedException e) { 
      e.printStackTrace(); 
    } 
  }
}

2、增強(qiáng)類,此類必須要實(shí)現(xiàn)增強(qiáng)方位接口

package com.gec.advice; 

import org.springframework.aop.MethodBeforeAdvice; 
import java.lang.reflect.Method; 

public class BeforeMethodAdvice implements MethodBeforeAdvice { 
  @Override
	public void before(Method method, Object[] objects, Object o) throws Throwable { 
    System.out.println("how are you"); 
  } 
}

3、配置文件

<?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:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd                          http://www.springframework.org/schema/util                                     http://www.springframework.org/schema/util/spring-util-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/aop                                    http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<aop:aspectj-autoproxy /> 
  <bean id="beforeMethodAdvice" class="com.gec.advice.BeforeMethodAdvice" /> 
  <bean id="hadoop" class="com.gec.target.Hadoop" /> 
  <aop:config> 
    <!--定義一個(gè)切面--> 
    <aop:advisor advice-ref="beforeMethodAdvice" pointcut="execution (* eatting(..))" /> 
  </aop:config> 
</beans>

4、測(cè)試

public static void main(String[] args) { 
  ApplicationContext ctx=new ClassPathXmlApplicationContext("beans.xml"); 
  Hadoop hadoop= (Hadoop) ctx.getBean("hadoop"); 
  hadoop.eatting(); 
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • springcloud feign傳輸List的坑及解決

    springcloud feign傳輸List的坑及解決

    這篇文章主要介紹了springcloud feign傳輸List的坑及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • SpringBoot實(shí)現(xiàn)物品收藏功能

    SpringBoot實(shí)現(xiàn)物品收藏功能

    這篇文章主要介紹了SpringBoot實(shí)現(xiàn)物品收藏功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • 詳解mybatis中的if-else的嵌套使用

    詳解mybatis中的if-else的嵌套使用

    本文主要介紹了mybatis中的if-else的嵌套使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • Java?Map.values()方法之如何獲取Map集合中的所有鍵值對(duì)象

    Java?Map.values()方法之如何獲取Map集合中的所有鍵值對(duì)象

    這篇文章主要介紹了Java?Map.values()方法之如何獲取Map集合中的所有鍵值對(duì)象問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • springboot中@Value的工作原理說(shuō)明

    springboot中@Value的工作原理說(shuō)明

    這篇文章主要介紹了springboot中@Value的工作原理,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • java實(shí)現(xiàn)單鏈表中的增刪改

    java實(shí)現(xiàn)單鏈表中的增刪改

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)單鏈表中的增刪改,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • Java==和equals的區(qū)別總結(jié)

    Java==和equals的區(qū)別總結(jié)

    在本文中小編給大家整理了關(guān)于Java==和equals的區(qū)別以及相關(guān)知識(shí)點(diǎn),有興趣的朋友們學(xué)習(xí)下。
    2019-03-03
  • Java構(gòu)建樹(shù)形菜單的實(shí)例代碼(支持多級(jí)菜單)

    Java構(gòu)建樹(shù)形菜單的實(shí)例代碼(支持多級(jí)菜單)

    這篇文章主要介紹了Java構(gòu)建樹(shù)形菜單的實(shí)例代碼(支持多級(jí)菜單),非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-09-09
  • Java中嵌入式MySQL的使用方法

    Java中嵌入式MySQL的使用方法

    這篇文章主要為大家詳細(xì)介紹了Java中嵌入式MySQL的使用方法,Java中如何使用嵌入MySQL,感興趣的小伙伴們可以參考一下
    2016-11-11
  • 帶你了解JAVA中的一些鎖概念

    帶你了解JAVA中的一些鎖概念

    今天小編就為大家分享一篇關(guān)于Java分布式鎖的概念與實(shí)現(xiàn)方式詳解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2021-08-08

最新評(píng)論