Spring AOP增强小例子
其他
2018-11-27 02:30:17
阅读次数: 0
- public interface ISomeService {
- public void some();
- }
- public class MyAdvice implements MethodBeforeAdvice{
- public void before(Method method, Object[] objects, Object o) throws Throwable {
- System.out.println("这是前置MethodBeforeAdvice");
- }
- }
- public class MyAfter implements AfterReturningAdvice {
- public void afterReturning(Object o, Method method, Object[] objects, Object o1) throws Throwable {
- System.out.println("这是后置");
- }
- }
- public class SomeService implements ISomeService{
- public void some(){
- System.out.println("这是测试 bean 代理");
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
- xmlns:aop="http://www.springframework.org/schema/aop"
-
- xmlns:context="http://www.springframework.org/schema/context"
-
- xmlns:p="http://www.springframework.org/schema/p"
-
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
-
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop.xsd
-
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd
- ">
-
-
- <bean id="some" class="cn.springAop.SomeService"></bean>
-
-
- <bean id="advice" class="cn.springAop.MyAdvice"></bean>
-
-
- <bean id="after" class="cn.springAop.MyAfter"></bean>
-
- <bean id ="DaiLi" class="org.springframework.aop.framework.ProxyFactoryBean">
-
- <property name="target" ref="some"></property>
-
- <property name="interceptorNames" value="advice,after"></property>
-
- <property name="proxyTargetClass" value="true"></property>
-
- </bean>
- </beans>
转载自blog.csdn.net/qq_36074218/article/details/76438624