基于Schema 配置切面:
1、切点定义的语言依然是AspectJ表达式语言
2、把不用AspectJ相关的注解定义切面,而是通过xml配置,相当于注解的xml表达的aop定义形式。
定义advice增强
public class LoginMonitorAspectj {
public static final ThreadLocal<Long> time = new ThreadLocal<Long>();
public void before(JoinPoint pjp) {
time.set(System.currentTimeMillis());
System.out.println("invoke before --------------------------------");
System.out.println(pjp.toLongString());
System.out.println(Arrays.toString(pjp.getArgs()));
}
public void afterReturning(JoinPoint pjp,User user) {
System.out.println("invoke afterReturning ---------------------------------");
System.out.println(user.toString());
System.out.println("times : "+(System.currentTimeMillis() - time.get()));
}
public void _exception(JoinPoint pjp,Exception ex) {
System.out.println("invoke _exception ---------------------------------");
System.out.println("times : "+(System.currentTimeMillis() - time.get()));
}
}
业务方法定义
@Service
public class LoginService implements ILoginService {
public User login(String username, String password) {
User user = new User();
System.out.println("in login method");
user.setPassword("123456");
user.setUsername("admin");
return user;
}
@MethodExecuteTimes
public void regist(String username, String password, String email, int age) {
System.out.println(Arrays.toString(new Object[]{username,password,age}));
}
}
配置applicationContext.xml
<context:component-scan base-package="org.job">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Service" />
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<aop:aspectj-autoproxy/>
<bean id="adviceMethods" class="org.job.user.aop.LoginMonitorAspectj"/>
<aop:config>
<aop:aspect ref="adviceMethods">
<aop:before pointcut="execution(* login(..))" method="before"/>
<aop:after-returning pointcut="execution(* login(..))" method="afterReturning" returning="user"/>
<aop:after-throwing pointcut="execution(* login(..))" method="_exception" throwing="ex"/>
</aop:aspect>
</aop:config>
</beans>
详细见附件
分享到:
相关推荐
spring-aop-1.1.1.jar spring-aop-1.2.6.jar spring-aop-1.2.9.jar spring-aop-2.0.2.jar spring-aop-2.0.6.jar spring-aop-2.0.7.jar spring-aop-2.0.8.jar spring-aop-2.0.jar spring-aop-2.5.1.jar spring-aop-...
开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE...
赠送jar包:spring-aop-5.2.0.RELEASE.jar; 赠送原API文档:spring-aop-5.2.0.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.2.0.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.2.0.RELEASE.pom;...
总结起来,"spring-aop-jar"涉及了Spring框架中的面向切面编程模块,包括Spring AOP和AspectJ的集成。通过理解和熟练使用这些组件,开发者可以有效地解耦关注点,提高代码的可维护性和可扩展性。在实际项目中,结合...
赠送jar包:spring-aop-5.0.8.RELEASE.jar; 赠送原API文档:spring-aop-5.0.8.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.0.8.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.0.8.RELEASE.pom;...
赠送jar包:spring-aop-5.0.10.RELEASE.jar; 赠送原API文档:spring-aop-5.0.10.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.0.10.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.0.10.RELEASE....
赠送jar包:spring-aop-5.3.10.jar; 赠送原API文档:spring-aop-5.3.10-javadoc.jar; 赠送源代码:spring-aop-5.3.10-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.3.10.pom; 包含翻译后的API文档:spring...
spring-aop-6.0.2.jar
spring-aop-5.3.22.jar Spring AOP provides an Alliance-compliant aspect-oriented programming implementation allowing you to define method interceptors and pointcuts to cleanly decouple code that ...
赠送jar包:spring-aop-5.3.12.jar; 赠送原API文档:spring-aop-5.3.12-javadoc.jar; 赠送源代码:spring-aop-5.3.12-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.3.12.pom; 包含翻译后的API文档:spring...
spring-aop-5.2.0.RELEASE
赠送jar包:spring-aop-4.3.20.RELEASE.jar; 赠送原API文档:spring-aop-4.3.20.RELEASE-javadoc.jar; 赠送源代码:spring-aop-4.3.20.RELEASE-sources.jar; 包含翻译后的API文档:spring-aop-4.3.20.RELEASE-...
赠送jar包:spring-aop-5.2.15.RELEASE.jar; 赠送原API文档:spring-aop-5.2.15.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.2.15.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.2.15.RELEASE....
spring-aop-3.2.5.RELEASE.jar
spring-aop-3.2.0.RELEASE.jar,一个Spring中AOP的jar包
赠送jar包:spring-aop-4.3.20.RELEASE.jar 赠送原API文档:spring-aop-4.3.20.RELEASE-javadoc.jar 赠送源代码:spring-aop-4.3.20.RELEASE-sources.jar 包含翻译后的API文档:spring-aop-4.3.20.RELEASE-...
赠送jar包:spring-aop-5.1.3.RELEASE.jar; 赠送原API文档:spring-aop-5.1.3.RELEASE-javadoc.jar; 赠送源代码:spring-aop-5.1.3.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-aop-5.1.3.RELEASE.pom;...
spring-aop-4.0.4.RELEASE 的jar包,亲测可用。。。。
spring-aop-5.0.4.RELEASE.jar。