最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

spring AOP的After增強(qiáng)實(shí)現(xiàn)方法實(shí)例分析

 更新時(shí)間:2020年01月08日 11:11:56   作者:cakincqm  
這篇文章主要介紹了spring AOP的After增強(qiáng)實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了spring面向切面AOP的After增強(qiáng)實(shí)現(xiàn)步驟與相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了spring AOP的After增強(qiáng)實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

一 配置

<?xml version="1.0" encoding="GBK"?>
<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"
   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.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-4.0.xsd
   http://www.springframework.org/schema/aop
   http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
   <!-- 指定自動(dòng)搜索Bean組件、自動(dòng)搜索切面類 -->
   <context:component-scan
      base-package="org.crazyit.app.service
      ,org.crazyit.app.aspect">
      <context:include-filter type="annotation"
        expression="org.aspectj.lang.annotation.Aspect" />
   </context:component-scan>
   <!-- 啟動(dòng)@AspectJ支持 -->
   <aop:aspectj-autoproxy />
</beans>

二 切面類

package org.crazyit.app.aspect;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.*;
// 定義一個(gè)切面
@Aspect
public class ReleaseAspect
{
  // 匹配org.crazyit.app.service包下所有類的、
  // 所有方法的執(zhí)行作為切入點(diǎn)
  @After("execution(* org.crazyit.app.service.*.*(..))")
  public void release()
  {
    System.out.println("模擬方法結(jié)束后的釋放資源...");
  }
}

三 接口

Hello

package org.crazyit.app.service;
public interface Hello {
   // 定義一個(gè)簡(jiǎn)單方法,模擬應(yīng)用中的業(yè)務(wù)邏輯方法
   void foo();
   // 定義一個(gè)addUser()方法,模擬應(yīng)用中的添加用戶的方法
   int addUser(String name, String pass);
}

World

package org.crazyit.app.service;
public interface World {
   // 定義一個(gè)簡(jiǎn)單方法,模擬應(yīng)用中的業(yè)務(wù)邏輯方法
   public void bar();
}

四 實(shí)現(xiàn)類

HelloImpl

package org.crazyit.app.service.impl;
import org.springframework.stereotype.Component;
import org.crazyit.app.service.*;
@Component("hello")
public class HelloImpl implements Hello
{
  // 定義一個(gè)簡(jiǎn)單方法,模擬應(yīng)用中的業(yè)務(wù)邏輯方法
  public void foo()
  {
    System.out.println("執(zhí)行Hello組件的foo()方法");
  }
  // 定義一個(gè)addUser()方法,模擬應(yīng)用中的添加用戶的方法
  public int addUser(String name , String pass)
  {
    System.out.println("執(zhí)行Hello組件的addUser添加用戶:" + name);
    if(name.length() < 3 || name.length() > 10)
    {
      throw new IllegalArgumentException("name參數(shù)的長(zhǎng)度必須大于3,小于10!");
    }
    return 20;
  }
}

WorldImpl

package org.crazyit.app.service.impl;
import org.springframework.stereotype.Component;
import org.crazyit.app.service.*;
@Component("world")
public class WorldImpl implements World {
  // 定義一個(gè)簡(jiǎn)單方法,模擬應(yīng)用中的業(yè)務(wù)邏輯方法
  public void bar() {
    System.out.println("執(zhí)行World組件的bar()方法");
  }
}

五 測(cè)試類

package lee;
import org.springframework.context.*;
import org.springframework.context.support.*;
import org.crazyit.app.service.*;
public class BeanTest {
  public static void main(String[] args) {
    // 創(chuàng)建Spring容器
    ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
    Hello hello = ctx.getBean("hello", Hello.class);
    hello.foo();
    hello.addUser("悟空", "7788");
    World world = ctx.getBean("world", World.class);
    world.bar();
  }
}

六 測(cè)試結(jié)果

執(zhí)行Hello組件的foo()方法
模擬方法結(jié)束后的釋放資源...
執(zhí)行Hello組件的addUser添加用戶:悟空
模擬方法結(jié)束后的釋放資源...
Exception in thread "main" java.lang.IllegalArgumentException:  name參數(shù)的長(zhǎng)度必須大于3,小于10!
     at  org.crazyit.app.service.impl.HelloImpl.addUser(HelloImpl.java:30)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native  Method)
     at  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     at  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:498)
     at  org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
     at  org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
     at  org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
     at  org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:43)
     at  org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
     at  org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
     at  org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
     at  org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
     at com.sun.proxy.$Proxy7.addUser(Unknown Source)
     at lee.BeanTest.main(BeanTest.java:26)

更多關(guān)于java相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Spring框架入門(mén)與進(jìn)階教程》、《Java數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Java操作DOM節(jié)點(diǎn)技巧總結(jié)》、《Java文件與目錄操作技巧匯總》和《Java緩存操作技巧匯總

希望本文所述對(duì)大家java程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Spring lazy-init 懶加載的原理小結(jié)

    Spring lazy-init 懶加載的原理小結(jié)

    lazy-init 是一個(gè)非常重要的屬性,可以優(yōu)化應(yīng)用的啟動(dòng)時(shí)間,尤其是在處理大量bean或者復(fù)雜依賴關(guān)系時(shí),可以顯著提高應(yīng)用的響應(yīng)速度,本文主要介紹了Spring lazy-init 懶加載的原理小結(jié),感興趣的可以了解一下
    2025-04-04
  • Mybatis-Plus之ID自動(dòng)增長(zhǎng)的設(shè)置實(shí)現(xiàn)

    Mybatis-Plus之ID自動(dòng)增長(zhǎng)的設(shè)置實(shí)現(xiàn)

    本文主要介紹了Mybatis-Plus之ID自動(dòng)增長(zhǎng)的設(shè)置實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • Java日期相關(guān)API的基本操作總結(jié)

    Java日期相關(guān)API的基本操作總結(jié)

    大概總結(jié)一下日期相關(guān)API操作原因是對(duì)于日期的操作我們開(kāi)發(fā)中還是很常見(jiàn)的,包括在數(shù)據(jù)庫(kù)中保存日期,以及之前String類中對(duì)字符串的一些處理開(kāi)發(fā)中都很常見(jiàn),希望對(duì)大家有所幫助
    2022-11-11
  • java實(shí)現(xiàn)汽車(chē)租賃系統(tǒng)

    java實(shí)現(xiàn)汽車(chē)租賃系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)汽車(chē)租賃系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • JAVA各種加密與解密方式總結(jié)大全

    JAVA各種加密與解密方式總結(jié)大全

    這篇文章主要給大家介紹了關(guān)于JAVA各種加密與解密方式總結(jié)的相關(guān)資料,加密是指對(duì)原來(lái)為明文的文件或數(shù)據(jù)按某種算法進(jìn)行處理,使其成為不可讀的一段代碼,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-07-07
  • 與近日火爆的ChatGPT聊Elasticsearch源碼

    與近日火爆的ChatGPT聊Elasticsearch源碼

    這篇文章主要為大家分享了與近日火爆的ChatGPT聊Elasticsearch源碼的話題內(nèi)容,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02
  • springboot?jpa?實(shí)現(xiàn)返回結(jié)果自定義查詢

    springboot?jpa?實(shí)現(xiàn)返回結(jié)果自定義查詢

    這篇文章主要介紹了springboot?jpa?實(shí)現(xiàn)返回結(jié)果自定義查詢方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • 解決rocketmq-client查詢手動(dòng)發(fā)送消息異常問(wèn)題

    解決rocketmq-client查詢手動(dòng)發(fā)送消息異常問(wèn)題

    這篇文章主要介紹了解決rocketmq-client查詢手動(dòng)發(fā)送消息異常問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • SpringBoot使用Swagger范例講解

    SpringBoot使用Swagger范例講解

    Swagger是一個(gè)規(guī)范和完整的框架,用于生成、描述、調(diào)用和可視化 Restful 風(fēng)格的 Web 服務(wù)。總體目標(biāo)是使客戶端和文件系統(tǒng)作為服務(wù)器以同樣的速度來(lái)更新。文件的方法、參數(shù)和模型緊密集成到服務(wù)器端的代碼,允許API來(lái)始終保持同步
    2022-07-07
  • java 中死鎖問(wèn)題的實(shí)例詳解

    java 中死鎖問(wèn)題的實(shí)例詳解

    這篇文章主要介紹了java 中死鎖問(wèn)題的實(shí)例詳解的相關(guān)資料,希望通過(guò)本文大家能夠理解掌握死鎖的問(wèn)題,需要的朋友可以參考下
    2017-09-09

最新評(píng)論

奇台县| 成武县| 嘉祥县| 浦县| 灵武市| 浮梁县| 万全县| 瑞安市| 南丹县| 项城市| 马鞍山市| 瓦房店市| 闵行区| 四平市| 察隅县| 芜湖市| 蒙城县| 安达市| 潍坊市| 陆河县| 徐水县| 会泽县| 仁怀市| 阜宁县| 高青县| 健康| 黄大仙区| 保亭| 阿坝县| 鄯善县| 延边| 东山县| 罗江县| 江孜县| 乌鲁木齐市| 柘荣县| 九龙坡区| 仁怀市| 丹巴县| 雅安市| 肇庆市|