国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

javaee spring aop 的五種通知方式

這篇具有很好參考價值的文章主要介紹了javaee spring aop 的五種通知方式。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

spring配置文件

<?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: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">

    <!--開啟包的掃描 -->
    <context:component-scan base-package="com.test" />

   <!-- 創(chuàng)建增強類對象 -->
    <bean id="myAdvice" class="com.test.advice.MyAdvice" />

    <!-- 織入 -->
    <aop:config>
          <!-- 定義切點-->
          <aop:pointcut id="pc" expression="execution(* com.test.service.impl.*.add(..))" />
          <!--切入 -->
          <aop:aspect ref="myAdvice">
              <!-- 將增強類對象myAdvice中的before方法切入到pc對應(yīng)的切點所在的方法前面 -->
              <aop:before method="before" pointcut-ref="pc" />

              <aop:after method="after" pointcut-ref="pc" />

              <aop:around method="around" pointcut-ref="pc" />

              <aop:after-returning method="afterReturning" pointcut-ref="pc" />

              <aop:after-throwing method="afterThrowing" pointcut-ref="pc" />

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


</beans>

切面類

package com.test.advice;

import org.aspectj.lang.ProceedingJoinPoint;

//增強類
public class MyAdvice {

    //將這個增強方法切入到service層的add方法前
    public void before()
    {
        System.out.println("添加用戶之前");
    }

    //目標方法執(zhí)行后(不管是出異常還是成功執(zhí)行)
    public void after()
    {
        System.out.println("添加用戶之后");
    }
    //環(huán)繞通知,用這個增強代碼替換掉目標方法
    public void around(ProceedingJoinPoint point) throws Throwable {
          System.out.println("執(zhí)行目標方法之前");
          point.proceed(); //放行切點處的方法(目標方法)
    }

    //目標方法成功執(zhí)行后
    public void afterReturning()
    {
       System.out.println("目標方法成功執(zhí)行后");
    }

    //目標方法出異常
    public void afterThrowing()
    {
        System.out.println("目標方法出異常以后才執(zhí)行");
    }

}

目標類

package com.test.service.impl;

import com.test.service.IUsersService;
import org.springframework.stereotype.Service;

@Service
public class UsersService implements IUsersService {

    @Override
    public void add()  {

        System.out.println("添加用戶...");
    }

    @Override
    public void update() {
        System.out.println("修改用戶...");
    }

    @Override
    public void delete() {
        System.out.println("刪除用戶...");
    }
}

測試結(jié)果

javaee spring aop 的五種通知方式,Mac開發(fā),java-ee,spring,java文章來源地址http://www.zghlxwxcb.cn/news/detail-692540.html

依賴

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

<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>org.example</groupId>
  <artifactId>testSpring06</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>testSpring06 Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <!-- Spring -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.3.18.Release</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>4.3.18.Release</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>4.3.18.Release</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>4.3.18.Release</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-expression</artifactId>
      <version>4.3.18.RELEASE</version>
    </dependency>

    <!-- aop -->
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>1.8.10</version>
    </dependency>

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

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

  </dependencies>

  <build>
    <finalName>testSpring06</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

到了這里,關(guān)于javaee spring aop 的五種通知方式的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • List集合的五種遍歷方式

    目錄 一、List五種遍歷方式 ?1、普通for遍歷 2、 增強for遍歷 ?3、Lambda表達式 ?4、迭代器遍歷 ?5、列表迭代器 方法 說明 迭代器遍歷 在遍歷的過程中需要刪除元素,請使用迭代器。 列表迭代器 在遍歷的過程中需要添加元素,請使用列表迭代器。 增強for遍歷 僅僅想遍歷,那

    2024年02月10日
    瀏覽(27)
  • Java遍歷Map的五種方式

    java中遍歷map一般有五種方法,從最早的Iterator,到j(luò)ava5支持的foreach,再到j(luò)ava8的Lambda表達式。 如果只是獲取key,或者value,推薦使用keySet或者values方式 如果同時需要key或者value推薦使用entrySet 如果需要在遍歷過程中刪除元素推薦使用Iterator 如果需要在遍歷過程中增加元素,可

    2024年02月03日
    瀏覽(26)
  • 微前端:qiankun的五種通信方式

    微前端:qiankun的五種通信方式

    今天盤點一下 qiankun 父子應(yīng)用的通信方式都有哪些,我發(fā)現(xiàn)了 5 種。 1、localStorage/sessionStorage 2、通過路由參數(shù)共享 3、官方提供的 props 4、官方提供的 actions 5、使用vuex或redux管理狀態(tài),通過shared分享 接下來我們一個一個進行說明 有人說這個方案必須主應(yīng)用和子應(yīng)用是同一個

    2024年03月21日
    瀏覽(27)
  • 微信小程序傳參的五種方式

    微信小程序傳參的五種方式

    大家好,今天和大家分享一下微信小程序頁面之間傳參的五種方式,這個的話也是有人問了我一嘴,然后現(xiàn)在我和大家分享一下。 使用GPT搜索的話給我的答案是純文字的描述,但是大致就是這樣: URL參數(shù)傳遞:可以將參數(shù)直接拼接在頁面的URL中,在打開目標頁面時,通過獲

    2024年02月06日
    瀏覽(25)
  • Vue路由跳轉(zhuǎn)的五種方式

    Vue路由跳轉(zhuǎn)的五種方式

    路由跳轉(zhuǎn)有兩種形式:聲明式導航、編程式導航 1. router-link 聲明式 prop= :to=“…” 相當與 router.push(…) router-link中鏈接如果是’ / \\\'開始,就是從根路由開始 如果開始不帶 ’ / \\\',則是從當前路由開始 例子 2. this.$router.push() 可追溯 編程式 router.push(…)//該方法的參數(shù)可以是一個

    2024年02月05日
    瀏覽(40)
  • springboot實現(xiàn)跨域的五種方式

    springboot實現(xiàn)跨域的五種方式

    出于瀏覽器的同源策略限制。同源策略(Sameoriginpolicy)是一種約定,它是瀏覽器最核心也最基本的安全功能,如果缺少了同源策略,則瀏覽器的正常功能可能都會受到影響。可以說Web是構(gòu)建在同源策略基礎(chǔ)之上的,瀏覽器只是針對同源策略的一種實現(xiàn)。 同源策略 同源策略會

    2024年02月05日
    瀏覽(25)
  • MAC磁盤空間不足怎么清理?MAC清理磁盤空間的五種方法

    MAC磁盤空間不足怎么清理?MAC清理磁盤空間的五種方法

    MAC磁盤空間不足怎么清理?當我們使用蘋果MAC一段時間后,就會有大量的垃圾文件占用磁盤空間,例如系統(tǒng)緩存文件、應(yīng)用程序緩存文件、備份和重復文件、舊版的應(yīng)用程序及其部件等,為了不影響電腦的后續(xù)使用,我們需要經(jīng)常清理磁盤空間,下面小編為大家?guī)砹薓AC清理

    2024年01月22日
    瀏覽(19)
  • 前端傳遞對象,后臺接收對象的五種方式

    前端傳遞對象,后臺接收對象的方式主要有以下幾種: 使用 @RequestBody 注解 :在 Spring Boot 控制器方法中使用 @RequestBody 注解將請求體中的 JSON 數(shù)據(jù)映射為 Java 對象。 使用 @ModelAttribute 注解 :在 Spring Boot 控制器方法中使用 @ModelAttribute 注解將 URL 參數(shù)或表單數(shù)據(jù)映射為 Java 對象

    2024年02月06日
    瀏覽(24)
  • Java調(diào)用python代碼的五種方式

    你還在糾結(jié)怎么樣在Java中調(diào)用python嗎?我們在實際工程項目問題中,經(jīng)常會碰到不同語言代碼之間互調(diào)的問題,比如此處的Java調(diào)用python(常見Java調(diào)用python寫的處理模型來完成數(shù)據(jù)處理等)。 讓我們來看看具體怎么操作吧! 說明: Java調(diào)用不帶參數(shù)的python代碼執(zhí)行 樣例代碼

    2024年02月09日
    瀏覽(28)
  • 【SpringBoot】 啟動后執(zhí)行方法的五種方式

    在 SpringBoot 工程 啟動后, 執(zhí)行方法的五種方式: 1、實現(xiàn) CommandLineRunner 接口 項目初始化完畢后,才會調(diào)用方法,提供服務(wù) 2、實現(xiàn) ApplicationRunner 接口 同 CommandLineRunner。只是傳參格式不一樣。CommandLineRunner:沒有任何限制;ApplicationRunner:key-value 3、實現(xiàn) ApplicationListener 接口

    2023年04月08日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包