-
ProxyFactoryBean을 이용한 선언적인 방법으로...
오라클자바커뮤니티에서 운영, 개발자 전문교육, 개인80%환급 오엔제이프로그래밍실무교육센터(www.onjprogramming.co.kr)
--------------------------
OnjWorld.java ---------------------------
package onj.aop.programming2;
public interface OnjWorld {
public void hello();
public void hello2() throws Exception;
}
------------------OnjWorldImpl.java-----------------
package onj.aop.programming2;
public class OnjWorldImpl{
public void hello() {
System.out.println("OnJ1에 오신 것을 환영합니다.");
}
public void hello2() throws Exception {
System.out.println("OnJ2에 오신 것을 환영합니다.");
}
}
------------OnjWorldBean.java------------
package onj.aop.programming2;
public class OnjWorldBean {
private OnjWorldImpl onjWorldImpl;
public void run() {
try {
onjWorldImpl.hello();
onjWorldImpl.hello2();
} catch(Exception e){
System.out.println("ERROR ::::"+ e);
}
}
public void setOnjWorldImpl(OnjWorldImpl onjWorldImpl) {
this.onjWorldImpl = onjWorldImpl;
}
}
------------OnjWorldExam.java------------
package onj.aop.programming2;
import org.springframework.context.support.GenericXmlApplicationContext;
public class OnjWorldExam {
public static void main(String[] args) {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.load("aop-onjworld.xml");
ctx.refresh();
OnjWorldBean bean1 = (OnjWorldBean)ctx.getBean("onjWorldBean1");
System.out.println("--------------------OnjWorld Bena Run()------------------");
bean1.run();
ctx.close();
}
}
--------------------aop-onjworld.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="onjWorldBean1" class="onj.aop.programming2.OnjWorldBean">
<property name="onjWorldImpl">
<ref local="onjWorld1" />
</property>
</bean>
<bean id="onjWorld1" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref local="onjWorldImpltarget" />
</property>
<property name="interceptorNames">
<list>
<value>beforeAdvisor</value>
<value>afterAdvisor</value>
<value>aroundAdvisor</value>
<value>throwsAdvisor</value>
</list>
</property>
</bean>
<bean id="onjWorldImpltarget" class="onj.aop.programming2.OnjWorldImpl" />
<bean id="beforeAdvice" class="onj.aop.programming2.BeforeLoggingAdvice" />
<bean id="afterAdvice" class="onj.aop.programming2.AfterLoggingAdvice" />
<bean id="aroundAdvice" class="onj.aop.programming2.AroundLoggingAdvice" />
<bean id="throwsAdvice" class="onj.aop.programming2.ThrowsLoggingAdvice" />
<bean id="beforeAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="advice">
<ref local="beforeAdvice"/>
</property>
<property name="pointcut">
<bean class="org.springframework.aop.aspectj.AspectJ__EXPRESSION__Pointcut">
<property name="__EXPRESSION__">
<value>execution(* hello2*(..))</value>
</property>
</bean>
</property>
</bean>
<bean id="afterAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="advice">
<ref local="afterAdvice"/>
</property>
<property name="pointcut">
<bean class="org.springframework.aop.aspectj.AspectJ__EXPRESSION__Pointcut">
<property name="__EXPRESSION__">
<value>execution(* hello2*(..))</value>
</property>
</bean>
</property>
</bean>
<bean id="aroundAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="advice">
<ref local="aroundAdvice"/>
</property>
<property name="pointcut">
<bean class="org.springframework.aop.aspectj.AspectJ__EXPRESSION__Pointcut">
<property name="__EXPRESSION__">
<value>execution(* hello2*(..))</value>
</property>
</bean>
</property>
</bean>
<bean id="throwsAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="advice">
<ref local="throwsAdvice"/>
</property>
<property name="pointcut">
<bean class="org.springframework.aop.aspectj.AspectJ__EXPRESSION__Pointcut">
<property name="__EXPRESSION__">
<value>execution(* hello2*(..))</value>
</property>
</bean>
</property>
</bean>
</beans>
-------------------- AfterLoggingAdvice.java---------------------
package onj.aop.programming2;
import java.lang.reflect.Method;
import org.springframework.aop.AfterReturningAdvice;
public class AfterLoggingAdvice implements AfterReturningAdvice{
public void afterReturning(Object arg0, Method arg1, Object[] arg2,
Object arg3) throws Throwable {
System.out.println(arg1.getName() + ":: 사후충고");
}
}
-------------------- AroundLoggingAdvice.java ---------------------
package onj.aop.programming2;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class AroundLoggingAdvice implements MethodInterceptor{
public Object invoke(MethodInvocation arg0) throws Throwable {
System.out.println("메소드실행전...");
Object returnedObj = arg0.proceed();
System.out.println("메소드실행후...");
return returnedObj;
}
}
-------------------- BeforeLoggingAdvice.java ---------------------
package onj.aop.programming2;
import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;
public class BeforeLoggingAdvice implements MethodBeforeAdvice {
public void before(Method method, Object[] args, Object target)
throws Throwable {
System.out.println("사전 충고받으시오::" + method);
}
}
-------------------- ThrowsLoggingAdvice.java ---------------------
package onj.aop.programming2;
import org.springframework.aop.ThrowsAdvice;
public class ThrowsLoggingAdvice implements ThrowsAdvice{
public void afterThrowing(Throwable throwable) {
System.out.println(">>>>>>>> 에러발생 " + throwable);
}
}
package onj.aop.programming2;
public interface OnjWorld {
public void hello();
public void hello2() throws Exception;
}
------------------OnjWorldImpl.java-----------------
package onj.aop.programming2;
public class OnjWorldImpl{
public void hello() {
System.out.println("OnJ1에 오신 것을 환영합니다.");
}
public void hello2() throws Exception {
System.out.println("OnJ2에 오신 것을 환영합니다.");
}
}
------------OnjWorldBean.java------------
package onj.aop.programming2;
public class OnjWorldBean {
private OnjWorldImpl onjWorldImpl;
public void run() {
try {
onjWorldImpl.hello();
onjWorldImpl.hello2();
} catch(Exception e){
System.out.println("ERROR ::::"+ e);
}
}
public void setOnjWorldImpl(OnjWorldImpl onjWorldImpl) {
this.onjWorldImpl = onjWorldImpl;
}
}
------------OnjWorldExam.java------------
package onj.aop.programming2;
import org.springframework.context.support.GenericXmlApplicationContext;
public class OnjWorldExam {
public static void main(String[] args) {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.load("aop-onjworld.xml");
ctx.refresh();
OnjWorldBean bean1 = (OnjWorldBean)ctx.getBean("onjWorldBean1");
System.out.println("--------------------OnjWorld Bena Run()------------------");
bean1.run();
ctx.close();
}
}
--------------------aop-onjworld.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="onjWorldBean1" class="onj.aop.programming2.OnjWorldBean">
<property name="onjWorldImpl">
<ref local="onjWorld1" />
</property>
</bean>
<bean id="onjWorld1" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref local="onjWorldImpltarget" />
</property>
<property name="interceptorNames">
<list>
<value>beforeAdvisor</value>
<value>afterAdvisor</value>
<value>aroundAdvisor</value>
<value>throwsAdvisor</value>
</list>
</property>
</bean>
<bean id="onjWorldImpltarget" class="onj.aop.programming2.OnjWorldImpl" />
<bean id="beforeAdvice" class="onj.aop.programming2.BeforeLoggingAdvice" />
<bean id="afterAdvice" class="onj.aop.programming2.AfterLoggingAdvice" />
<bean id="aroundAdvice" class="onj.aop.programming2.AroundLoggingAdvice" />
<bean id="throwsAdvice" class="onj.aop.programming2.ThrowsLoggingAdvice" />
<bean id="beforeAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="advice">
<ref local="beforeAdvice"/>
</property>
<property name="pointcut">
<bean class="org.springframework.aop.aspectj.AspectJ__EXPRESSION__Pointcut">
<property name="__EXPRESSION__">
<value>execution(* hello2*(..))</value>
</property>
</bean>
</property>
</bean>
<bean id="afterAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="advice">
<ref local="afterAdvice"/>
</property>
<property name="pointcut">
<bean class="org.springframework.aop.aspectj.AspectJ__EXPRESSION__Pointcut">
<property name="__EXPRESSION__">
<value>execution(* hello2*(..))</value>
</property>
</bean>
</property>
</bean>
<bean id="aroundAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="advice">
<ref local="aroundAdvice"/>
</property>
<property name="pointcut">
<bean class="org.springframework.aop.aspectj.AspectJ__EXPRESSION__Pointcut">
<property name="__EXPRESSION__">
<value>execution(* hello2*(..))</value>
</property>
</bean>
</property>
</bean>
<bean id="throwsAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="advice">
<ref local="throwsAdvice"/>
</property>
<property name="pointcut">
<bean class="org.springframework.aop.aspectj.AspectJ__EXPRESSION__Pointcut">
<property name="__EXPRESSION__">
<value>execution(* hello2*(..))</value>
</property>
</bean>
</property>
</bean>
</beans>
-------------------- AfterLoggingAdvice.java---------------------
package onj.aop.programming2;
import java.lang.reflect.Method;
import org.springframework.aop.AfterReturningAdvice;
public class AfterLoggingAdvice implements AfterReturningAdvice{
public void afterReturning(Object arg0, Method arg1, Object[] arg2,
Object arg3) throws Throwable {
System.out.println(arg1.getName() + ":: 사후충고");
}
}
-------------------- AroundLoggingAdvice.java ---------------------
package onj.aop.programming2;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class AroundLoggingAdvice implements MethodInterceptor{
public Object invoke(MethodInvocation arg0) throws Throwable {
System.out.println("메소드실행전...");
Object returnedObj = arg0.proceed();
System.out.println("메소드실행후...");
return returnedObj;
}
}
-------------------- BeforeLoggingAdvice.java ---------------------
package onj.aop.programming2;
import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;
public class BeforeLoggingAdvice implements MethodBeforeAdvice {
public void before(Method method, Object[] args, Object target)
throws Throwable {
System.out.println("사전 충고받으시오::" + method);
}
}
-------------------- ThrowsLoggingAdvice.java ---------------------
package onj.aop.programming2;
import org.springframework.aop.ThrowsAdvice;
public class ThrowsLoggingAdvice implements ThrowsAdvice{
public void afterThrowing(Throwable throwable) {
System.out.println(">>>>>>>> 에러발생 " + throwable);
}
}
평일주간(9:30~18:20) 개강
(4/22)[기업100%환급]PL/SQL,ORACLE HINT,TUNING
(4/29)[기업100%환급]자바기초에서 JDBC, Servlet/JSP까지
(4/29)C#4.0,ADO.NET,Network 프로그래밍
(5/12)[기업100%환급]Spring ,MyBatis,Hibernate실무과정
(5/12)[기업100%환급]SQL기초에서 Schema Object까지
(5/12)안드로이드개발자과정
평일야간(19:00~21:50) 개강
(4/22)웹퍼블리싱 마스터
(4/23)안드로이드개발자과정
(4/24)Spring3.X, MyBatis, Hibernate실무과정
(5/16)자바웹(JSP,Spring,MyBatis,XPlatform)프로젝트과정
(5/16)JAVA&WEB프레임워크실무과정
(5/16)C#,ASP.NET마스터
(5/16)SQL초보에서실전전문가까지
주말(10:00~18:00) 개강
(4/20)웹퍼블리싱 마스터
(5/03)안드로이드개발자과정
(5/17)자바기초에서JSP,Ajax,jQuery,Spring3.2,MyBatis까지
(5/17)SQL초보에서실전전문가까지
(5/17)개발자를위한PLSQL,SQL튜닝,힌트
(5/17)Spring3.X, MyBatis, Hibernate실무과정
(5/17)C#,ASP.NET마스터
주말저녁(18:30~22:20) 개강
(5/17)JAVA,JDBC,JSP,Servlet,Ajax,jQUERY,Spring,MyBatis,Hibernate
(5/17)SQL기초에서 Schema Object까지
댓글 없음:
댓글 쓰기