aspectj

@AspectJ pointcut for subclasses of a class with an annotation

泄露秘密 提交于 2019-11-28 01:15:36
问题 I'm looking for a pointcut that matches method executions in classes that subclass a class with a specific annotation. The excellent AspectJ cheat sheet helped me to create the following pointcut: within(@my.own.annotations.AnnotationToMatch *) && execution(* *(..)) This matches all method calls of a class A that carries the @AnnotationToMatch, but not method of a class B that extends A. How can I match both? 回答1: public aspect AnnotatedParentPointcutAspect { //introducing empty marker

Cannot find org.aspectj.weaver.reflect.ReflectionWorld

与世无争的帅哥 提交于 2019-11-27 23:10:52
I'm setting a Spring 3.2.3 + Hibernate 4 project in Eclipse 4.3. When I add the code <tx:annotation-driven transaction-manager="transactionManager"/> to my context I start getting the following error in every single bean: Build path is incomplete. Cannot find class file for org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException Now, I added both AspectJ Tools and Cglib dependencies to my project and the JARs are there, including the class it can't find. The application runs normally, and Spring is managing sessions and transactions successfully. I've searched for a solution but

Pointcut matching methods with annotated parameters

那年仲夏 提交于 2019-11-27 22:29:21
I need to create an aspect with a pointcut matching a method if: it is annoted with MyAnnotationForMethod One of its parameters (can have many) is annotated with @MyAnnotationForParam (but can have other annotations as well). The aspect class look like this @Pointcut("execution(@MyAnnotationForMethod * *(..,@aspects.MyAnnotationForParam Object, ..)) && args(obj)") void myPointcut(JoinPoint thisJoinPoint, Object obj) { } @Before("myPointcut(thisJoinPoint , obj)") public void doStuffOnParam(JoinPoint thisJoinPoint, Object obj) { LOGGER.info("doStuffOnParam :"+obj); } The annoted method

SpringAOP事务—AspectJ配置

久未见 提交于 2019-11-27 22:07:29
SpringAOP配置: 必须代理类 每个Service必须注册一个代理类 AOP-XML配置 SpringAOP注解: 每个Service类的每个方法都有添加注解 AOP-注解配置 AspectJ注解配置:一般推荐使用这种 在基于之前的jar包下新添 apsetj-weaver.jar spring-aspectj.jar xml配置 <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!--配置事务事务通知,引入tx约束 --> <tx:advice id="txadvice" transaction-manager="transactionManager"> <!--配置事务属性 --> <tx:attributes> <tx:method name="open*" isolation="DEFAULT" propagation="REQUIRED"/> <tx:method name="buy*" isolation="DEFAULT" propagation=

AspectJ in Android: pointcut call(* Activity.onCreate(..)) doesn't pick out Activity.onCreate() calls

百般思念 提交于 2019-11-27 20:53:22
I am using AspectJ in my Android project and I'd like to write a pointcut that catches all the calls to onCreate() and onDestroy() of my activities. I am quite new to AspectJ, so probably I am missing something here but why this: pointcut createActivity(Activity a) : target(a) && execution(* Activity.onCreate(..)) && within(com.test.activities..*); works and this: target(a) && call(* Activity.onCreate(..)) && within(com.test.activities..*); doesn't work? Nice to see other people adventuring into aspectJ and Android :-) When using aspectJ with android you are limited to compile-time weaving,

spring事务管理源码解析之其他

霸气de小男生 提交于 2019-11-27 20:49:27
本文转自“天河聊技术”微信公众号 说在前面 基于注解的spring声明式事务管理源码解析已经完毕了,第一篇文章中提到spring事务管理模式有两种形式一种是proxy,一种是aspectj,基于proxy已经解析完毕了,默认的也是proxy,声明式事务管理配置一种是基于注解,一种是基于xml配置文件的,最后再补充下基于aspectj这种事务模式和基于xml配置的声明式事务管理的源码解析。 正文 基于aspectj的声明事务管理模式源码解析 找到这个方法org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser#parse @Override @Nullable public BeanDefinition parse(Element element, ParserContext parserContext) { // 注册事务监听器工厂 registerTransactionalEventListenerFactory(parserContext); // 获取模式属性 String mode = element.getAttribute("mode"); if ("aspectj".equals(mode)) { // mode="aspectj"

Spring / @Transactional with AspectJ is totally ignored

ε祈祈猫儿з 提交于 2019-11-27 19:20:58
问题 I use Spring-Data Neo4j 2.2.0-RELEASE. (my following issue would be applicable to any other kind of entity mapping, why not JPA) In my project, I have a public method annotated with @Transactional Spring's annotation, since I want to update/save an entity inside it: public class MeetingServices { private UserRepository userRepository; private MeetingRepository meetingRepository; public void setUserRepository(UserRepository userRepository) { this.userRepository = userRepository; } public void

Maven: compile aspectj project containing Java 1.6 source

橙三吉。 提交于 2019-11-27 19:06:48
Primary Question What I want to do is fairly easy. Or so you would think. However, nothing is working properly. Requirement: Using maven, compile Java 1.6 project using AspectJ compiler. Note: Our code cannot compile with javac. That is, it fails compilation if aspects are not woven in (because we have aspects that soften exceptions). Update 2/21/2011: There are two equally viable solutions to this (both cases use the aspectj-maven-plugin in conjuction with the maven-compiler-plugin ): Add <failOnError>false</failOnError> to the compiler plugin (thanks Pascal Thivent ) Add <phase>process

Spring Dependency Injecting an annotated Aspect

雨燕双飞 提交于 2019-11-27 18:56:29
问题 Using Spring I've had some issues with doing a dependency injection on an annotated Aspect class. CacheService is injected upon the Spring context's startup, but when the weaving takes place, it says that the cacheService is null. So I am forced to relook up the spring context manually and get the bean from there. Is there another way of going about it? Here is an example of my Aspect: import org.apache.log4j.Logger; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang

logging with AOP in spring?

ぃ、小莉子 提交于 2019-11-27 18:02:28
I am new to spring in my office . So there is no guidance for me. I need to implement the logging with the AOP using the log4j . I have implemented the logging without AOP in basic spring MVC example ? Also did the small sample in AOP using the aspectJ without logging (just made the Sysout ) ? I don't know how to integrate it ? Can any one please give me a start up idea? Good answers are definitely appreciated ... Spring makes it really easy for us to make use of AOP. Here's a simple logging example: @Aspect public class MyLogger { private Logger log = Logger.getLogger(getClass()); @After(