日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Spring AOP XML配置及注解配置

發布時間:2024/10/6 417 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring AOP XML配置及注解配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一.XML配置切面類

1.日志切面類

//切面類注解配置加兩個注解 @Aspect @Component public class LoggerAspect {public Object log(ProceedingJoinPoint joinPoint) throws Throwable {System.out.println("start log:" + joinPoint.getSignature().getName());Object object = joinPoint.proceed();System.out.println("end log:" + joinPoint.getSignature().getName());return object;} }

2.業務類

//業務類 @Component public class ProductService {public void doSomeService(){System.out.println("doSomeService");} }

3.spring.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:tx="http://www.springframework.org/schema/tx"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"><!-- 注解方式aop--><component-scan base="ServiceClass"/><component-scan base="LoggAspect"/><aop:aspectj-autoproxy/><!--xml配置aop--><bean id="productService" class="service"/><bean id="loggerAspect" class="LoggerAspect"><aop:config><aop:pointcut id="pointCut" expression="execution(* package.class.*(..))"<aop:aspect id="logAspect" ref="loggerAspect"><aop:round method="log" ref="pointcut"></aop:aspect></aop:config></beans>

?

?

?

總結

以上是生活随笔為你收集整理的Spring AOP XML配置及注解配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。