Spring MethodBeforeAdvice使用例子
2012-07-27 18:07
351 查看
/article/4135857.html
MethodBeforeAdvice该拦截器会在调用dean的方法前执行
Java代码
![](http://javapub.iteye.com/images/icon_copy.gif)
![](http://javapub.iteye.com/images/icon_star.png)
![](http://javapub.iteye.com/images/spinner.gif)
import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;
public class DaoMethodBeforeAdvice
implements MethodBeforeAdvice{
public void before(Method arg0, Object[] arg1, Object arg2)
throws Throwable {
System.out.println("[DaoMethodBeforeAdvice]:" + arg0 +
" : " + arg1[0]);
}
}
配置文件信息
Java代码
![](http://javapub.iteye.com/images/icon_copy.gif)
![](http://javapub.iteye.com/images/icon_star.png)
![](http://javapub.iteye.com/images/spinner.gif)
<bean id="beforeDaoAdvice"
class="com.zakisoft.workspace.initcompt.advice.DaoMethodBeforeAdvice"></bean>
<bean id="afterDaoAdvice"
class="com.zakisoft.workspace.initcompt.advice.DaoMethodAfterAdvice"></bean>
<bean id="throwsDaoAdvice"
class="com.zakisoft.workspace.initcompt.advice.DaoThrowsAdvice"></bean>
<bean id="aroundAdvice"
class="com.zakisoft.workspace.initcompt.advice.DaoMethodAroundAdvice"></bean>
<bean id="daoAopService"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="mybatisDaoBean"></property>
<property name="interceptorNames">
<list>
<value>beforeDaoAdvice</value>
<value>afterDaoAdvice</value>
<value>throwsDaoAdvice</value>
<value>aroundAdvice</value>
</list>
</property>
</bean>
完整代码请参考附件
src.zip (73.5 KB)
下载次数: 72
MethodBeforeAdvice该拦截器会在调用dean的方法前执行
Java代码
![](http://javapub.iteye.com/images/icon_copy.gif)
![](http://javapub.iteye.com/images/icon_star.png)
![](http://javapub.iteye.com/images/spinner.gif)
import java.lang.reflect.Method;
import org.springframework.aop.MethodBeforeAdvice;
public class DaoMethodBeforeAdvice
implements MethodBeforeAdvice{
public void before(Method arg0, Object[] arg1, Object arg2)
throws Throwable {
System.out.println("[DaoMethodBeforeAdvice]:" + arg0 +
" : " + arg1[0]);
}
}
import java.lang.reflect.Method; import org.springframework.aop.MethodBeforeAdvice; public class DaoMethodBeforeAdvice implements MethodBeforeAdvice{ public void before(Method arg0, Object[] arg1, Object arg2) throws Throwable { System.out.println("[DaoMethodBeforeAdvice]:" + arg0 + " : " + arg1[0]); } }
配置文件信息
Java代码
![](http://javapub.iteye.com/images/icon_copy.gif)
![](http://javapub.iteye.com/images/icon_star.png)
![](http://javapub.iteye.com/images/spinner.gif)
<bean id="beforeDaoAdvice"
class="com.zakisoft.workspace.initcompt.advice.DaoMethodBeforeAdvice"></bean>
<bean id="afterDaoAdvice"
class="com.zakisoft.workspace.initcompt.advice.DaoMethodAfterAdvice"></bean>
<bean id="throwsDaoAdvice"
class="com.zakisoft.workspace.initcompt.advice.DaoThrowsAdvice"></bean>
<bean id="aroundAdvice"
class="com.zakisoft.workspace.initcompt.advice.DaoMethodAroundAdvice"></bean>
<bean id="daoAopService"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="mybatisDaoBean"></property>
<property name="interceptorNames">
<list>
<value>beforeDaoAdvice</value>
<value>afterDaoAdvice</value>
<value>throwsDaoAdvice</value>
<value>aroundAdvice</value>
</list>
</property>
</bean>
<bean id="beforeDaoAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoMethodBeforeAdvice"></bean> <bean id="afterDaoAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoMethodAfterAdvice"></bean> <bean id="throwsDaoAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoThrowsAdvice"></bean> <bean id="aroundAdvice" class="com.zakisoft.workspace.initcompt.advice.DaoMethodAroundAdvice"></bean> <bean id="daoAopService" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="target" ref="mybatisDaoBean"></property> <property name="interceptorNames"> <list> <value>beforeDaoAdvice</value> <value>afterDaoAdvice</value> <value>throwsDaoAdvice</value> <value>aroundAdvice</value> </list> </property> </bean>
完整代码请参考附件
src.zip (73.5 KB)
下载次数: 72
相关文章推荐
- 使用Spring(14)Spring AOP APIs(AfterReturningAdvice,MethodInterceptor,MethodBeforeAdvice)
- spring AOP详解之--前置增强 (MethodBeforeAdvice)
- Spring的MethodBeforeAdvice实现原理探究&&实现一个简单的Advice
- Spring AOP Advice接口-MethodBeforeAdvice+AfterReturningAdvice
- Spring AOP Advice接口-MethodBeforeAdvice+AfterReturningAdvice
- Spring AOP练习 中提示 The hierarchy of MyMethodBeforeAdvice types is inconsistent
- Spring MethodBeforeAdvice
- spring-aop之MethodBeforeAdvice实现
- Spring的MethodBeforeAdvice实现原理探究&&实现一个简单的Advice
- Spring AOP 之 BeforeAdviceDemo
- 在Spring中使用replaced-method来进行方法替换
- org.springframework.beans.factory.config.MethodInvokingFactoryBean的使用
- spring-cloud-config service使用svn作为远程的例子
- 错误处理:The hierarchy of the type MyMethodBeforeAdvice is inconsistent
- Spring中配合hibernate使用的简单例子
- spring 使用注解事物管理例子
- spring HiddenHttpMethodFilter使用问题
- Spring的JdbcTemplate使用update或insert操作的三种使用例子
- @classmethod, @staticmethod和@property这三个装饰器的使用对象是在类中定义的函数。下面的例子展示了它们的用法和行为:
- 使用springdata操作mongodb的例子