67,513
社区成员
发帖
与我相关
我的任务
分享
<bean id="actionBeanNameProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*Service</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>logService</value>
</list>
</property>
</bean>
/**
*
*/
package com.zuxiang.autoproxy.service;
/**
* @author zuxiang
*
*/
public interface AnnotationService {
void doAnnotationService();
}
/**
*
*/
package com.zuxiang.autoproxy.service;
import org.springframework.stereotype.Service;
/**
* @author zuxiang
*
*/
@Service
public class AnnotationServiceImpl implements AnnotationService{
@Override
public void doAnnotationService() {
// TODO Auto-generated method stub
System.out.println("\n\tAnnotationServiceImpl ---- doAnnotationService() \n");
}
}
/**
*
*/
package com.zuxiang.autoproxy.service;
/**
* @author zuxiang
*
*/
public interface XMLService {
void doXMLServcie();
}
/**
*
*/
package com.zuxiang.autoproxy.service;
/**
* @author zuxiang
*
*/
public class XMLServiceImpl implements XMLService{
@Override
public void doXMLServcie() {
// TODO Auto-generated method stub
System.out.println("\n\tXMLServiceImpl ---- doXMLServcie() \n");
}
}
/**
*
*/
package com.zuxiang.autoproxy;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
/**
* @author zuxiang
*
*/
public class AutoproxyInterceptor implements MethodInterceptor{
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
String methodStr = "method '" + invocation.getMethod().getName() + "' of class [" +
invocation.getThis().getClass().getName() + "]";
System.out.println("begig ......" + methodStr);
Object object = invocation.proceed();
System.out.println("end ......" + methodStr + "\n");
return object;
}
}
package com.zuxiang;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.zuxiang.autoproxy.service.AnnotationService;
import com.zuxiang.autoproxy.service.XMLService;
public class Test {
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
//UserService us = (UserService) ac.getBean("userServiceImpl");
XMLService xmlService = (XMLService) ac.getBean("xmlService");
AnnotationService annotationService = (AnnotationService) ac.getBean("annotationServiceImpl");
//us.getUser();
//us.update();
//us.delete();
//us.remove();
//us.insert();
xmlService.doXMLServcie();
annotationService.doAnnotationService();
}
}