proxy 객체를 xml에 구현
<beans>
<bean id="객체명" class="경로" p:변수=값 p:변수=값 ... p:변수=값 />
<bean id="곁다리업무명"
class="MethodInterceptor를 임플리먼트 해서 구현할 클래스 경로"/>
<bean id=proxy class="proxy 자바 내장 경로">
<property name="내가 지은 객체명 아무거나" ref="">
<!-- 참조형 ref로 객체를 가져옴-->
<property name="interceptorNames">
<list>
<value> 곁다리 업무명(id)기입 </vlaue>
</list>
</property>
</bean>
</beans>
//곁다리 업무를 구현할 클래스 Side
public class 곁다리업무Class implements MethodInterceptor{
@Override
public Object invoke(MethodInvocation invocation) throws Throwable{
long start = System.currentTimeMillis();
/*-------------- top -----------*/
result = invocation.proceed();
//본업무 진행
/*-------------- top -----------*/
long end = System.currentTimeMillis();
message = (start - end) + "ms 소요되었습니다";
System.out.println(message);
return result;
}
}
public static void main(String[] args)
{
ApplicationContext context =
new ClassPathXmlApplicationContext("../../xml파일 패키지 경로");
Exam proxy = context.getBean("proxy");
System.out.printf("total is %d \n, proxy.total());
System.out.printf("avg is %d\n, proxy.avg());
}