aspectj

What is AspectJ good for? [closed]

ぃ、小莉子 提交于 2019-11-27 05:04:44
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . First let me note, that I use AspectJ and I like it, but what else can I do with it. I know AspectJ can be/is used for Logging. In some cases it is used for Transaction controlling – mostly implemented in conjunction with annotations. AspectJ can also be used to enhance classes

Spring autowired bean for @Aspect aspect is null

﹥>﹥吖頭↗ 提交于 2019-11-27 03:42:59
I have the following spring configuration: <context:component-scan base-package="uk.co.mysite.googlecontactsync.aop"/> <bean name="simpleEmailSender" class="uk.co.mysite.util.email.simple.SimpleEmailSenderImplementation"/> <aop:aspectj-autoproxy/> Then I have an aspect: @Aspect public class SyncLoggingAspect { @Autowired private SimpleEmailSender simpleEmailSender @AfterReturning(value="execution(* uk.co.mysite.datasync.polling.Poller+.doPoll())", returning="pusher") public void afterPoll(Pusher pusher) { simpleEmailSender.send(new PusherEmail(pusher)); } } This aspect works (I can hit a

java利用AOP 实现操作日志记录(一)

让人想犯罪 __ 提交于 2019-11-27 03:41:07
除springMvc外需要引入@Aspect注解依赖: <!-- AOP --> <!-- https://mvnrepository.com/artifact/aopalliance/aopalliance --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.6.11</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.6.11</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.1_3</version> </dependency> 自定义注解标签: @Target({ ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited public @interface logAnnotation { /** *

Adding AspectJ to pom.xml changed Java version with Maven, why?

给你一囗甜甜゛ 提交于 2019-11-27 03:13:44
问题 UPDATE: here is my maven-compiler-plugin configuration: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> I work on a multi-project application that I build with Maven. We decided to add AspectJ so I added the following code to pom.xml in the top level project: (from the official documentation) <project> ... <dependencies> ... <dependency>

Aspectj and catching private or inner methods

走远了吗. 提交于 2019-11-27 02:55:01
问题 I've configureg AspectJ with Spring and it works fine when "catching" public methods called from out of the class. Now I want do something like this: public class SomeLogic(){ public boolean someMethod(boolean test){ if(test){ return innerA(); } else { return innerB(); } } private boolean innerA() {// some logic} private boolean innerA() {// some other logic} } SomeLogic is a SpringBean. The methods innerA() and innerB() could be declared as private or public - the method someMethod() is

AspectJ pointcut on constructor object

坚强是说给别人听的谎言 提交于 2019-11-27 02:27:18
问题 I need to inject few methods to every initialized object using AspectJ. I thought using this : pointcut vistaInjection(Object o) : initialization(java.lang.Object.new() ) && target(o) && !within(objectAspect); before(Object o): methodInjection(o){System.err.println("INIT");} to pointcut initialization of object, so I can inject these methods directly into the object that is part of every other object. However, it does't work. Do you have any idea why? Or what may be an other way how to make

What is a short example of inter-type declarations in AspectJ which demonstrates the usefulness of the approach?

馋奶兔 提交于 2019-11-27 02:20:57
问题 I first thought about using ITDs to define the private static final Logger logger = ... for some unrelated cases, but it doesn't look enough like an obvious improvement to use that as a demonstration example. Is there some standard/suggested example of ITD usage, which people should use for teaching purposes? 回答1: I'd like to add another example to Adam's answer. Using aspects is a way to improve modularization of your software, as well as OOP is, except that OOP is applied "vertically",

How to enable aspectj compile time weaving with Java 7 and maven

断了今生、忘了曾经 提交于 2019-11-27 00:30:25
问题 I have a project which currently works with java 6 and compile time weaving. We use the following pom to enable spring aspects and our own ones: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.4</version> <configuration> <showWeaveInfo>true</showWeaveInfo> <source>1.6</source> <target>1.6</target> <Xlint>ignore</Xlint> <complianceLevel>1.6</complianceLevel> <encoding>UTF-8</encoding> <verbose>false</verbose> <aspectLibraries>

Use of proxies in Spring AOP

走远了吗. 提交于 2019-11-27 00:23:25
I am reading a book, which talks about enabling AspectJ support in Spring AOP. Given below is a paragraph taken from the book: To enable AspectJ annotation support in the Spring IoC container, you only have to define an empty XML element aop:aspectj-autoproxy in your bean configuration file. Then, Spring will automatically create proxies for any of your beans that are matched by your AspectJ aspects. For cases in which interfaces are not available or not used in an application’s design, it’s possible to create proxies by relying on CGLIB. To enable CGLIB, you need to set the attribute proxy

Cannot find org.aspectj.weaver.reflect.ReflectionWorld

不羁的心 提交于 2019-11-26 23:17:00
问题 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