일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- Mac
- context
- Eclipse
- resource
- port
- 네트워크
- Quartz
- find
- maVen
- GIT
- web.xml
- ssh
- vscode
- VirtualBox
- lsof
- IntelliJ
- profile
- Source
- tomcat
- Windows 10
- 줄바꿈 문자
- xargs
- bash
- Windows
- netsh
- grep
- JavaScript
- plugin
- import
- 단축키
- Today
- Total
develog
[Spring] Spring3 AOP 설정, xml or java 본문
<필요 jar>
pom.xml
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.1.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>3.1.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>3.1.1.RELEASE</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.6.8</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.6.8</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.2</version> </dependency> |
<방법1>
spring-config.xml
<context:component-scan base-package="com.my" /> <bean id="myAspect" class="com.LoggingAspect" /> <aop:config> <aop:pointcut id="myPointcut" expression="execution(* *..*.*(..))" /> <aop:aspect ref="myAspect"> <aop:before method="before" pointcut-ref="myPointcut" /> <aop:after-returning method="afterReturning" pointcut-ref="myPointcut" returning="retVal" /> </aop:aspect> </aop:config> |
LoggingAspect.java
package com.my; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.Signature; public class LoggingAspect { public void before(JoinPoint joinPoint) { System.out.println(); System.out.println(">> before()"); }
public void afterReturning(JoinPoint joinPoint, Object retVal) { System.out.println(); System.out.println(">> afterReturning()"); }
} |
<방법2>
LoggingAspect.java
package com.my; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.Signature; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; @Configuration @EnableAspectJAutoProxy @Aspect public class LoggingAspect { @Before("execution(* *..*.*(..))") public void before(JoinPoint joinPoint) { System.out.println(); System.out.println(">> before()"); }
@AfterReturning("execution(* *..*.*(..))") public void afterReturning(JoinPoint joinPoint, Object retVal) { System.out.println(); System.out.println(">> afterReturning()"); }
} |
'Dev > Spring' 카테고리의 다른 글
[Spring] beans.xml 설정1, 기본 (0) | 2015.08.28 |
---|---|
[Spring] beans.xml (0) | 2015.06.04 |
[Spring] static method injection (0) | 2014.11.11 |
[Spring] Spring 2.5, Properties #2 (0) | 2014.11.11 |
[Spring] Spring 2.5, Properties (0) | 2014.11.10 |