aspectj

Is there “skip weaving flag” in Maven? (exclude AspectJ)

你离开我真会死。 提交于 2019-12-23 02:13:48
问题 I build our multi-project application with Maven(lots of pom.xml-s). We recently introduced AspectJ, however I suspect AspectJ contributes to performance problems. In order to be sure, I'd like to build the application this time without AspectJ and see how it performs. But I would not really like to remove all AspectJ related stuff from pom.xml, so it would be handy if there was some kind of flag or something that could exclude AspectJ from build. Is there any? Update: this does not seem to

Pass object between before and after advice?

纵饮孤独 提交于 2019-12-23 01:54:47
问题 Is it possible to create an object in a before advice and pass it to an after advice? For instance, if I have the aspect: public aspect LoggingAspect { pointcut allMethods() : execution(* com.foo.Bar.*(..)); before() : allMethods() { SomeObject foo = makeSomeObject(); } after() : allMethods() { // access foo? } } I can't directly reference foo since it's not in scope (triggers a compiler error). Is there some context available to both advices that I can store foo inside? Background: I intend

AspectJ pointcut for constructor using java.lang.reflection

↘锁芯ラ 提交于 2019-12-23 01:13:38
问题 The following example is a reduction of the real problem in that it tries to simplify is as much as possible. I have a java interface, and several objects that implement that interface, like: public interface Shape{ public void draw(); public void erase(); public boolean isDrawn(); } public class Square implements Shape{ @Override public void draw(){ //TODO: method implementation } @Override public void erase(){ //TODO: method implementation } Override public boolean isDrawn(){ //TODO: method

AspectJ pointcut for constructor using java.lang.reflection

可紊 提交于 2019-12-23 01:13:11
问题 The following example is a reduction of the real problem in that it tries to simplify is as much as possible. I have a java interface, and several objects that implement that interface, like: public interface Shape{ public void draw(); public void erase(); public boolean isDrawn(); } public class Square implements Shape{ @Override public void draw(){ //TODO: method implementation } @Override public void erase(){ //TODO: method implementation } Override public boolean isDrawn(){ //TODO: method

Make object spring managed

余生长醉 提交于 2019-12-23 01:12:54
问题 How can I get an already existing object spring managed? I would like to hook it up to Springs AoP capabilities using aspectj . I know this to be a challenge since Spring AoP uses dynamic proxies which probably are created along with the object. Why do I need this? I have a third-party class which takes a constructor argument which is only known in runtime , hence it seems I cannot add it to my applicationContext or use springs FactoryBean interface for construction. Is there any other way? I

Make object spring managed

爱⌒轻易说出口 提交于 2019-12-23 01:12:14
问题 How can I get an already existing object spring managed? I would like to hook it up to Springs AoP capabilities using aspectj . I know this to be a challenge since Spring AoP uses dynamic proxies which probably are created along with the object. Why do I need this? I have a third-party class which takes a constructor argument which is only known in runtime , hence it seems I cannot add it to my applicationContext or use springs FactoryBean interface for construction. Is there any other way? I

Spring @Configurable基本用法

微笑、不失礼 提交于 2019-12-22 23:48:43
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 关于 @Configurable 的用法, Spring文档 有详细的描述,不过由于看得比较粗略,后面实际使用的时候踩了不少坑。这个注解有以下几个用途: 为非Spring管理的对象注入Spring Bean 非Spring管理的对象,这里指的是我们自己new的对象,比如 Dog dog = new Dog() ,这个dog对象的生命周期不是由Spring管理的,而是我们自己创建的对象,根据文档的说法,我们只要在类上面加上 @Configurable 注解,就可以让Spring来配置这些非Spring管理的对象了,即为它们注入需要的依赖(实际上还有很多额外的工作要做)。下面有个例子 // Account类,使用new操作符号手动创建,不交由Spring Container管理 @Configurable(autowire = Autowire.BY_TYPE) public class Account { @Autowired Dog dog; public void output(){ System.out.println(dog); } } 上面的 Account 类使用的是 @Configurable ,而不是 @Configuration , @Configuration 类似于XML配置里面的

How to attach a pointcut to a to a method of class residing inside a .jar file using command line?

天涯浪子 提交于 2019-12-22 16:43:27
问题 I am new to AOP . I have created a class in HookShow.java file: public class HookShow { void show(String msg) { System.out.println("In show :"+msg); } public static void main(String[] args) { HookShow cm=new HookShow(); cm.show("called from main method"); } } then i compiled it and added the generated .class file into .jar file using : jar cf HSHOW.jar HookShow.class Now i have a HSHOW.jar. Now i am creating an aspect that has a pointcut which is executed on the call of show() . But i dont

Self-invocation shouldn't be adviced but it does

与世无争的帅哥 提交于 2019-12-22 15:02:55
问题 I'm getting a weird behavior by Spring AOP AspectJ: self-invocation shouldn't be adviced, but in my application it does. From Spring documentation: However, once the call has finally reached the target object, the SimplePojo reference in this case, any method calls that it may make on itself, such as this.bar() or this.foo(), are going to be invoked against the this reference, and not the proxy. This has important implications. It means that self-invocation is not going to result in the

Getting a Template/Generic java.lang.reflect.Method object from org.aspectj.lang.ProceedingJoinPoint

本小妞迷上赌 提交于 2019-12-22 12:54:25
问题 This question would not have existed if AspectJ worked the same way as EJB interceptors work. Consider basic scenario the EJB-interceptor way: @AroundInvoke public Object log(final InvocationContext ctx) throws Exception { // do stuff before final Object result = ctx.proceed(); // do stuff after return result; } Now I need the Method object that's being intercepted. Here I can simply do this: Method method = ctx.getMethod(); And that's it, after this I will be inspecting intercepted method's