SpringBoot中進行「方面」程式設計。

2021-10-25 15:59:54 字數 2077 閱讀 4051

目錄

1、pom檔案,需要新增web和aop的boot依賴。

2、定義controller和service。

3、編寫切面類

4、執行boot專案

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-aop

package xyz.jangle.springboot.demo.ctrl;

import org.springframework.beans.factory.annotation.autowired;

import org.springframework.web.bind.annotation.restcontroller;

import xyz.jangle.springboot.demo.service.aservice;

@restcontroller

public class testctrl

public static void main(string args)

}

service:

package xyz.jangle.springboot.demo.service;

/** * @author jangle

* @email [email protected]

* @time 2023年2月8日 下午4:48:37

* */

public inte***ce aservice

package xyz.jangle.springboot.demo.service.impl;

import org.springframework.stereotype.service;

import xyz.jangle.springboot.demo.service.aservice;

/** * @author jangle

* @email [email protected]

* @time 2023年2月8日 下午4:49:06

* */

@service

public class aserviceimpl implements aservice

}

package xyz.jangle.springboot.demo.aop;

import org.aspectj.lang.proceedingjoinpoint;

import org.aspectj.lang.annotation.around;

import org.aspectj.lang.annotation.aspect;

import org.aspectj.lang.annotation.pointcut;

import org.springframework.stereotype.component;

/** *

* 方面程式設計

* @author jangle

* @email [email protected]

* @time 2023年2月8日 上午11:39:01

* */

// 1、這個類稱之為切面

@aspect

@component

public class myaopdemo

// 3、此處定義通知

@around("servicepointcut()")

public object around(proceedingjoinpoint joinpoint) catch (throwable e)

return proceed;

}}

訪問:

程式輸出結果:

just so so ...

這是方法的輸出

around after 1111

Spring Boot中進行Junit測試

spring boot新版本預設使用junit5,pom依賴為 dependency groupid org.springframework.boot groupid artifactid spring boot starter test artifactid scope test scope ex...

Makefile中進行巨集定義

實際上是gcc命令支援 d巨集定義,相當於c中的全域性 define gcc d name gcc d name definition makefile中可以定義變數 和巨集很像 但是是給make直譯器用的,對所編譯的檔案完全沒有作用。mstar 巨集定義方式 字串定義方式和值定義方式 cc tvo...

在VBA中進行除錯

只要從您的專案中觸發 vba就會執行。從簡單的開啟表單到單擊命令按鈕,各種各樣的物件事件都可能引起這種情況。當某些事情無法按預期工作時,您如何才能準確確定出什麼問題以及在 好吧,這就是本文可以為您提供的幫助。對於每個office應用程式,當然包括access,都有乙個整合的偵錯程式。要開啟偵錯程式視...