Spring 기초: AOP 프로 그래 밍 (5)
4949 단어 spring
Schema 기반 AOP 프로 그래 밍
AspectJ 를 바탕 으로 하 는 AOP 프로 그래 밍 은 우리 의 프로 그래 밍 수 요 를 만족 시 킬 수 있 습 니 다. 왜 여기 서 Schema 를 바탕 으로 하 는 논 리 를 해 야 합 니까? 여기 에는 두 가지 이유 가 있 습 니 다.
1. 자바 언어 는 5.0 에 이 르 러 서 야 주해 기능 을 지원 하기 때문에 5.0 이전 버 전에 서도 AspectJ 의 편 의 를 체험 하려 면 특별한 방법 이 필요 하 다.
2. AspectJ 는 절단면 Advisor 를 대상 으로 프로 그래 밍 할 수 없 지만 Schema 는 가능 합 니 다.
선행 강화:
public class AdviceMethods {
public void preGreeting() {
System.out.println("--how are you--");
}
}
테스트 코드:
public class SchemaProxyTest {
public static void main(String[] args) {
String configLocation = "com/firethewhole/maventest08/schema/beans.xml";
ApplicationContext ctx = new ClassPathXmlApplicationContext(configLocation);
Waiter naiveWaiter = (Waiter) ctx.getBean("naiveWaiter");
Waiter naughtyWaiter = (Waiter) ctx.getBean("naughtyWaiter");
naiveWaiter.greetTo("John");
naughtyWaiter.greetTo("John");
}
}
출력:
--how are you-- NaiveWaiter.greet to John NaughtyWaiter: greet to John
저 희 는 주석 이나 AspectJ 와 관련 된 기능 을 사용 하지 않 았 습 니 다. XML 설정 류 와 관련 된 Bean 과 도 같은 효 과 를 거 두 었 습 니 다.
후방 증강:
설정 파일 에 반환 값 을 연결 할 수 있 습 니 다.
서 라운드 강화:
서 라운드 강화 연결 점 정보 연결 가능
public void aroundMethod(ProceedingJoinPoint pjp) throws Throwable {
System.out.println(" :" + pjp.getTarget().getClass());
System.out.println(" :" + pjp.getArgs()[0]);
pjp.proceed();
System.out.println(" :" + pjp.getTarget().getClass());
}
이상 증강 던 지기:
public void afterThrowingMethod(IllegalArgumentException iae) {
System.out.println(" :" + iae.getMessage());
}
여기 귀속 클래스 이상 정보 입 니 다.
최종 강화:
이상 이 있 든 없 든 집행 할 것 이다.
소개 강화:
바 인 딩 매개 변수 강화:
public void bindParams(int num, String name) {
System.out.println("-----bindParams-----");
System.out.println("name:" + name);
System.out.println("num:" + num);
System.out.println("-----bindParams-----");
}
public class SchemaProxyTest {
public static void main(String[] args) {
String configLocation = "com/firethewhole/maventest08/schema/beans.xml";
ApplicationContext ctx = new ClassPathXmlApplicationContext(configLocation);
Waiter naiveWaiter = (Waiter) ctx.getBean("naiveWaiter");
((NaiveWaiter)naiveWaiter).smile("John", 2);
}
}
출력:
-----bindParams----- name:John num:2 -----bindParams----- NaiveWaiter.smile to John 2 times
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
thymeleaf로 HTML 페이지를 동적으로 만듭니다 (spring + gradle)지난번에는 에서 화면에 HTML을 표시했습니다. 이번에는 화면을 동적으로 움직여보고 싶기 때문에 입력한 문자를 화면에 표시시키고 싶습니다. 초보자의 비망록이므로 이상한 점 등 있으면 지적 받을 수 있으면 기쁩니다! ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.