Spring AOP XML配置及注解配置
生活随笔
收集整理的這篇文章主要介紹了
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配置及注解配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: springmvc jsp页面提交表单乱
- 下一篇: 导入jar时出现invalid LOC