Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- w3school
- html
- 데이터베이스
- 이것이 자바다
- php
- rinux
- 라우터
- sql
- 네트워크관리사
- 참조타입
- 원형그래프
- 오라클
- 정처기필기
- Cisco
- 자바
- Java
- 리눅스
- javaee
- 정보처리기사
- autoset
- VLAN
- 버추얼머신
- jsp연결
- 네트워크
- Oracle
- jsp
- ciscopacket
- NCS
- ospf
- cisco packet
Archives
- Today
- Total
기록해! 정리해!
어노데이션 기본 AOP - Before 어드바이스 본문
1.
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<context:component-scan base-package="com.springbook.biz" />
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
</beans>
========================================================================
package com.springbook.biz.common;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Service;
@Service
@Aspect
public class LogAdvice {
@Pointcut("execution(* com.springbook.biz..*ServiceImpl.*(..))")
public void allPointcut() {}
@Before("allPointcut()")
public void printLog() {
System.out.println("[공통로그] 비즈니스 로직 수행 전 동작");
}
@Pointcut("execution(* com.springbook.biz..*ServiceImpl.get*(..))")
public void getPointcut() {}
}
2.
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<context:component-scan base-package="com.springbook.biz" />
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
</beans>
=========================================================================
package com.springbook.biz.common;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Service;
@Service
@Aspect
public class BeforeAdvice {
// 포인트 컷
@Pointcut("execution(* com.springbook.biz..*ServiceImpl.*(..))")
public void allPointcut() {}
// 어드바이스
@Before("allPointcut()")
void beforeLog(JoinPoint jp) {
String method = jp.getSignature().getName(); // 비즈니스 로직 메소드 이름 불러오기
Object[] args = jp.getArgs(); // 비즈니스 로직 메소드의 매개변수에 들어오는 args 값 읽어오기
System.out.println("[사전처리]" + method + "()메소드 ARGS 정보: " + args[0].toString() );
}
}
=========================================================================
package com.springbook.biz.common;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Service;
@Service
@Aspect
public class BeforeAdvice {
// 포인트 컷
@Pointcut("execution(* com.springbook.biz..*ServiceImpl.*(..))")
public void allPointcut() {}
// 어드바이스
@Before("allPointcut()")
void beforeLog(JoinPoint jp) {
String method = jp.getSignature().getName(); // 비즈니스 로직 메소드 이름 불러오기
Object[] args = jp.getArgs(); // 비즈니스 로직 메소드의 매개변수에 들어오는 args 값 읽어오기
System.out.println("[사전처리]" + method + "()메소드 ARGS 정보: " + args[0].toString() );
}
}
'Spring' 카테고리의 다른 글
Spring JDBC 방법 2 (0) | 2022.09.22 |
---|---|
Spring JDBC 방법 (0) | 2022.09.22 |
JoinPoint 메소드 사용하기 (0) | 2022.09.22 |
AOP 사용하기 (0) | 2022.09.22 |
비즈니스 컴포넌트 실습 II ( 어노테이션으로 수정 ) (0) | 2022.09.22 |
Comments