目标bean,showValues(String value)方法执行作为连接点
Java代码
public class InitializingBeanNameClass
public String showValues(String
value)
{
System.out.println("目标方法执行:");
System.out.println("传入参数:String arg: " + value);
return value;
}
}
public class InitializingBeanNameClass
public String showValues(String
value)
{
System.out.println("目标方法执行:");
System.out.println("传入参数:String arg: " + value);
return value;
}
}
切面,bindMethodArgTest(String argvalue)方法作为通知
Java代码
public class BindArgs {
public void bindMethodArgTest(String
argvalue) {
System.out.println("BindMethodArgTest通知,通过args(argvalue,..)绑定showValues(java.lang.String,..)第一个参数......");
System.out.println("参数:" + argvalue);
}
}
public class BindArgs {
public void bindMethodArgTest(String
argvalue) {
System.out.println("BindMethodArgTest通知,通过args(argvalue,..)绑定showValues(java.lang.String,..)第一个参数......");
System.out.println("参数:" + argvalue);
}
}
Java代码
<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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<aop:aspectj-autoproxy/>
<aop:config>
<aop:aspect id="bindArgs" ref="bindArgsAspectBean">
<aop:before method="bindMethodArgTest" arg-names="
argvalue" pointcut="execution( * com.spring.ch4.*.showValues(..)) and args(
argvalue)" />
</aop:aspect>
</aop:config>
<bean id="nameBean" class="com.spring.ch4.InitializingBeanNameClass">
<property name="firstName" value="shen"/>
</bean>
<bean id="bindArgsAspectBean" class="com.spring.ch4.pointcut.xml.BindArgs" />
</beans>
<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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<aop:aspectj-autoproxy/>
<aop:config>
<aop:aspect id="bindArgs" ref="bindArgsAspectBean">
<aop:before method="bindMethodArgTest" arg-names="
argvalue" pointcut="execution( * com.spring.ch4.*.showValues(..)) and args(
argvalue)" />
</aop:aspect>
</aop:config>
<bean id="nameBean" class="com.spring.ch4.InitializingBeanNameClass">
<property name="firstName" value="shen"/>
</bean>
<bean id="bindArgsAspectBean" class="com.spring.ch4.pointcut.xml.BindArgs" />
</beans>
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("com/spring/ch4/pointcut/xml/pointcut-tests.xml");
InitializingBeanNameClass nameBean = (InitializingBeanNameClass) context.getBean("nameBean");
System.out.println("=== GOING TO testBeforeAdvice ===");
nameBean.showValues("方法参数绑定");
System.out.println("=== FINISHED testBeforeAdvice ===");
}
执行结果
=== GOING TO testBeforeAdvice ===
BindMethodArgTest通知,通过args(argvalue,..)绑定showValues(java.lang.String,..)第一个参数......
参数:方法参数绑定
目标方法执行:
传入参数:String arg: 方法参数绑定
=== FINISHED testBeforeAdvice ===
这是我从java eye 提问模块中发现的。
[size=xx-small]回答者是:whistler [/size]
分享到:
相关推荐
AOP修改方法的参数,如何截取指定方法的参数并修改其参数值
spring AOP 理论知识点总结.wpsspring AOP 理论知识点总结.wpsspring AOP 理论知识点总结.wps
西门子如何从AOP中读取参数组pdf,西门子如何从AOP中读取参数组
NULL 博文链接:https://jackyin5918.iteye.com/blog/1918076
基于Spring boot + maven,以注解+AOP方式实现的java后端项目接口参数校验框架。迄今为止使用最简单、最容易理解的参数校验方案。博客地址:https://blog.csdn.net/weixin_42686388/article/details/104009771
before方法会在目标对象的指定方法执行之前 被执行,在before方法种,你可以取得指定方法的Method实例、参数列表和目标对象,在before方法执行完后,目标对象上的方法将会执行,除 非在before方法种抛出异常。...
使用 Spring AOP 进行方法耗时监测的好处有以下几点: 1. 代码实现简单,易于维护:使用 Spring AOP 可以将耗时监测的逻辑与业务逻辑进行解耦,避免业务逻辑代码的冗余和代码维护难度的提高。 2. 安全性高:使用 ...
AOP根据方法名匹配织入
Spring_IOC_AOP总结,有代码详细讲解了springIOC和AOP的功能,是你学习三大框架的必备
个人对spring实现AOP的四种方法总结!部分可能不是太完整!
spring aop spring aop spring aop spring aop spring aop spring aop spring aop spring aop spring aop
aop切面拦截单个方法实例
AOP 面向方面编程 技术总结 AOP 面向方面编程 技术总结
NULL 博文链接:https://conkeyn.iteye.com/blog/2354644
Spring Boot + validation + AOP 请求参数校验 一、validation 校验注解 通用 @Null 被注释的属性必须为 null @NotNull被注释的属性必须不为 null @AssertTrue 被注释的属性必须为 true @AssertFalse 被注释的属性...
SpringBoot下的Spring——DAY04——动态代理总结、AOP、自定义注解进行拦截、动态获取注解参数、通知方法 1.动态代理总结 1.1 JDK动态代理特点 1.2 CGlib动态代理 1.2.1 CGLib特点说明 1.3 动态代理的作用 2 Spring...
一直对AOP面向切面编程的理解很模糊的同学可以看看。
AOP面向切面编程(Aspect Oriented Programming),是通过预编译方式和运行期动态代理实现程序功能的统一...下面这篇文章主要给大家介绍了关于利用C#实现AOP常见的几种方法,需要的朋友可以参考借鉴,下面来一起看看吧。
springaop的注解和xml配置,也包括aop处理参数的方法
AOP技术总结 2