AOP Spring AOP Spring Framework AOP OOP AOP
- Slides: 53
AOP 개념 및 Spring의 AOP 기능
Spring Framework – AOP 절차적 프로그래밍 OOP AOP
Spring Framework – AOP 다음 문제의 정답은? 1 11 12 1121 122111 112213 ? ? ? ?
Spring Framework – AOP 사고의 전환
Spring Framework - AOP 요구사항!! • Message. Renderer, Message. Provider의 모든 메써드 시작과 종료시 “Method. Name 시작”, “Method. Name 종료”라는 Logging 메시지를 출력한다.
Spring Framework - AOP
Spring Framework - AOP 요구사항 변경!! • Message. Renderer, Message. Provider의 모든 메써드 시작과 종료시 “Method. Name Start”, “Method. Name End”라는 Logging 메시지를 출력한다.
Spring Framework - AOP 삽질의 연속
Spring Framework - AOP
Spring Framework – AOP
지금까지의 구현 방법 - User. Service. Impl public User find. User(String user. Id) throws User. Not. Found. Exception { if (logger. is. Debug. Enabled()) { logger. debug("find. User() 시작"); logger. debug("User ID : " + user. Id); } User user = user. DAO. find. User(user. Id); if (user == null) { throw new User. Not. Found. Exception(context. get. Message( "user. notfound. exception", new Object[] { user. Id }, null)); } if (logger. is. Debug. Enabled()) { logger. debug(user. Id + " 사용자 정보 : " + user); } if (logger. is. Debug. Enabled()) { logger. debug("find. User() 종료"); } return user; }
Spring Framework – AOP를 이용한 해결 방법
AOP 적용 - User. Service. Impl public User find. User(String user. Id) throws User. Not. Found. Exception { User user = user. DAO. find. User(user. Id); if (user == null) { throw new User. Not. Found. Exception(context. get. Message( "user. notfound. exception", new Object[] { user. Id }, null)); } if (logger. is. Debug. Enabled()) { logger. debug(user. Id + " 사용자 정보 : " + user); } return user; }
AOP 적용 – Logging. Advice public class User. Logging. Advice implements Method. Interceptor { protected final Log logger = Log. Factory. get. Log(get. Class()); public Object invoke(Method. Invocation invocation) throws Throwable { String class. Name = invocation. get. This(). get. Class(). get. Name(); if (logger. is. Debug. Enabled()) { logger. debug(class. Name + ". " + invocation. get. Method(). get. Name() + "()" + " 시작!!"); Object[] args = invocation. get. Arguments(); if ((args != null) && (args. length > 0)) { for (int i = 0; i < args. length; i++) { logger. debug("Argument[" + i + "] : " + args[i]); } } } //Target 클래스의 메써드를 실행한다. Object ret. Val = invocation. proceed(); if (logger. is. Debug. Enabled()) { logger. debug(class. Name + ". " + invocation. get. Method(). get. Name() + "()" + " 종료!!"); } return ret. Val; } }
Spring Framework – AOP
Logging Poincut public class Logging. Pointcut extends Static. Method. Matcher. Pointcut { public boolean matches(Method method, Class cls) { if( "find. User". equals(method. get. Name()) ) { return true; } return false; } public Class. Filter get. Class. Filter() { return new Class. Filter() { public boolean matches(Class cls) { return (cls == User. Service. Impl. class) || (cls == My. SQLUser. DAO. class); } }
Spring Framework – AOP
Spring Framework - AOP
Spring Framework - AOP
Spring Framework – AOP Advice • Join Point에서 Aspect에 의하여 실행되는 Action을 의미 • 예를 들어 Logging Aspect일 경우 Join Point에서 Logging 하는 것을 의미한다.
Spring Framework – AOP Advice 의 종류 • Before advice : Join Point 전에 실행되는 Advice. • Around advice : Join Point 전, 후에 실행되는 Advice. • After returning advice : Joint Point 완료된 후에 실행되는 Advice • After throwing advice : Exception Throwing이 될 때 실행되는 Advice • After (finally) advice : After returning advice, After throwing advice 모든 경우에 실행
Spring Framework – AOP Before Advice @Before("com. xyz. myapp. System. Architecture. data. Access. Operation()") public void do. Access. Check() { //. . . }
Spring Framework – AOP After Returning Advice @After. Returning( pointcut="com. xyz. myapp. System. Architecture. data. Access. Operation()", returning="ret. Val") public void do. Access. Check(Object ret. Val) { //. . . }
Spring Framework – AOP After Throwing Advice @After. Throwing( pointcut="com. xyz. myapp. System. Architecture. data. Access. Operation()", throwing="ex") public void do. Recovery. Actions(Data. Access. Exception ex) { //. . . }
Spring Framework – AOP After (finally) Advice @After("com. xyz. myapp. System. Architecture. data. Access. Operation()") public void do. Release. Lock() { //. . . }
Spring Framework – AOP Around Advice @Around("com. xyz. myapp. System. Architecture. business. Service()") public Object do. Basic. Profiling(Proceeding. Join. Point pjp) throws Throwable { // start stopwatch Object ret. Val = pjp. proceed(); // stopwatch return ret. Val; }
Spring Framework – AOP Pointcut • Join Point들을 선택하는 규칙을 정의하는 것. Weaving Rule을 정의하는 것
Spring Framework – AOP Pointcut의 종류 – Spring 1. x • Static. Method. Matcher. Pointcut • Dynamic. Method. Matcher. Pointcut • Perl 5 Regexp. Method. Pointcut • Jdk. Regexp. Method. Pointcut • Name. Match. Method. Pointcut • Composable. Pointcut • Control. Flow. Pointcut
Spring Framework – AOP Pointcut의 종류 – Spring 2. 0 • execution • within • this • target • args
Spring Framework – AOP Pointcut의 종류 – Spring 2. 0 • @target • @args • @within • @annotation • &&, ||, !
Spring Framework – AOP Pointcut의 예제 – Spring 2. 0 • execution(* com. xyz. service. Account. Service. *(. . )) • within(com. xyz. service. *) • this(com. xyz. service. Account. Service) • @target(org. springframework. transaction. annotation. Transactional) • @within(org. springframework. transaction. annotation. Transactional) • @args(com. xyz. security. Classified)
Spring Framework – AOP Aspect • 하나의 Crosscutting Concern을 Aspect로 정의 가능 • Advice와 Pointcut이 결합되어 Aspect가 된다. • 예를 들어 Transaction, Security등이 하나의 Aspect가 된다.
Spring Framework – AOP Weaving • Advcie, Pointcut, Target Object로 분리된 것을 하나로 결합하는 것을 의미 • Weaving 작업을 지원하는 Tool(Aspect. J, Spring AOP)을 Weaver라 지칭
Spring Framework - AOP를 적용 후
Spring Framework - AOP
Spring Framework - AOP 요구사항!! • User. Service. Impl의 update. User()는 “admin”, remove. User는 “admin” 권한을 가진 사용자만 접근이 가능하도록 해라.
Spring Framework - AOP
- Oop
- Oop.oop~f
- Oop.oop~f
- Oop.oop~f
- Javaero
- Spring aop static method
- What is aop
- Jboss aop
- What is aop
- Handlerinterceptoradapter
- Aop
- Montage sommateur inverseur
- Aop network
- What are the months of spring?
- Four seasons korean movie
- Spring framework overview
- Spring framework architecture
- Introduction to spring framework
- Dispositional framework vs regulatory framework
- Sample of theoretical framework
- Conceptual framework vs theoretical framework
- Theoretical framework vs conceptual framework
- Theoretical framework
- Dispositional framework vs regulatory framework
- Oop
- Principiile oop
- Oop array
- Oop principles
- Sejarah oop
- Aggregation in oop
- Oop
- Sejarah oop
- Imeasureable
- Oop history
- P oop
- Mermaid is an example of in oop
- Blackjack python object oriented
- Penyembunyian kerumitan pada program dalam oop disebut
- Oop presentation topics
- Oop review
- Oop en geslote vraekaartjies
- Structured analysis vs object oriented analysis
- Ooa ood
- Oop cs
- What is sa/sd methodology?
- Extends oop
- What is encapsulation
- Pillar of oop
- E balagurusamy object oriented programming with c++
- Flowchart oop
- Polymorphism in oop
- Materi oop
- Safersys snapshot
- Programozási nyelvek csoportosítása