aspectj

How can I log private methods via Spring AOP?

吃可爱长大的小学妹 提交于 2019-12-04 16:41:42
I am not able to log the private methods using spring aop performance logging. Below is the configuration I am using below configuration <aop:config proxy-target-class="true"> <aop:pointcut id="allServiceMethods" expression="execution(* com.mycom.app.abc..*.*(..))"/> <aop:advisor pointcut-ref="allServiceMethods" advice-ref="performanceMonitor" order="2"/> </aop:config> I am having cglib jar on my class path. You have to use compile time weaving instead of the proxy usage for Spring AOP. From Spring AOP - Supported Pointcut Designators Due to the proxy-based nature of Spring’s AOP framework,

AspectJ constructor force factory pattern

Deadly 提交于 2019-12-04 16:39:38
I want to change the object return from call to a constuctor FROM public class A { public A(){ } public String sayHello() { return "hello"; } public String foo() { return "foo"; } } TO public class AWrapped extends A { private A wrapped; public AWrapped() { super(); } public AWrapped(A pWrapped) { wrapped=pWrapped; } public String foo() { return wrapped.foo(); } public String sayHello { return "gday mate"; } } What i want to do is to change the object that is returned from a call A a = new A(); a.sayHello() returns "gday mate" a is an instaceof AWrapped I understand that this would usually be

Check if aspectjweaver (or any javaagent) is loaded

て烟熏妆下的殇ゞ 提交于 2019-12-04 16:35:06
Is there a (pref portable) way to check if The JVM has been stated with a particular -javaagent ? In particular I'm interested to know if the aspectj load time weaver has loaded or not. (I'm trying to provide a helpful error msg in the case of incorrect startup). kriegaex The following code shows a way to determine any -javaagent:... JVM arguments, a way to check if the AspectJ weaving agent entry point class (the one mentioned in the manifest entry Premain-Class: of aspectjweaver.jar ) is loaded. The former just proves that the argument was given on the command line, not that the agent was

aspectj for Android studio - where is AJDT plugin

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 15:57:10
How do i install AJDT for android studio. I know there is one for eclipse but i cant find anything in android studio. What i would like to do is run security checks on every one of my method calls before they launch. I've tried from this site AJDT but this is for eclipse. Android Studio is an Android-aware version of IntelliJ. IntelliJ has no tooling support for AspectJ. There are two solutions that I can think of: Use Eclipse and ADT, but you probably don't want to do that. Use Annotation Style AspectJ and let Android Studio treat the aspect code as Java code. You won't get any cross

how to write an aspectj itd to add an annotation to a method?

安稳与你 提交于 2019-12-04 15:45:16
I am new to aspectj but I want to write an aspectj ITD which allows me to put an annotation on a method. Can anybody help me with it? Thanks Shekhar I was able to do it. This is how you can do it declare @method :public * MyUser+.persist() : @Profiled; this for example matches all Methods of classes which have a @Entity annotation (be sure you have the import in your aspectj-file) declare @method : public * ((@Entity *)).*(..) : @PreAuthorize("denyAll"); but i'm having a hard time to also specify a package, suggestions? 来源: https://stackoverflow.com/questions/4615333/how-to-write-an-aspectj

AspectJ Pointcut on Methods with Multiple Annotations

瘦欲@ 提交于 2019-12-04 15:31:54
Use load-time weaving, pure AspectJ. We have 2 annotations @Time and @Count , and a few annotated methods. @Time (name="myMethod1Time") @Count (name="myMethod1Count") public void myMethod1(){..}; @Time (name="myMethod2Time") public void myMethod2(){..}; @Count (name="myMethod3Count") public void myMethod3(){..}; Now I am defining my own around aspect for myMethod1 which has multiple annotations: // multiple annotations, not working @Around("@annotation(time) && @annotation(count)) public Object myAspect(Time time, Count count) {..} This doesn't work. However, capture method myMethod2 works

APT and AOP in the same project, using Maven

岁酱吖の 提交于 2019-12-04 14:56:50
I have to use Annotation Processing (apt) and AspectJ in the same Maven project. Both work for themselves, but I need to create aspects based on code created by apt. So I would need binary weaving (the original source files are extended by apt). How can I enable binary weaving within a maven project? I know the only standard option is to supply a dependency using the weaveDependencies parameter, but this is awful. Is there any other way? OK, I could embed the AspectJ ant tasks using the Maven Antrun Plugin but I'd hate to resort to that. I am apparently the only one who can answer my own

How to add a field to a custom-annotated class using AspectJ

最后都变了- 提交于 2019-12-04 14:32:42
问题 To add a field to some specific class with aspectj we do package com.test; public class MyClass { private String myField; } public aspect MyAspect { private String MyClass.myHiddenField; } How do we add a field to a class that is annotated with some custom annotation? example usage : if class is annotated with @CustomLoggable add a Logger field and some methods. or if method has the @ReadLocked annotation then class will have a ReentrantReadWriteLock field and the appropriate logic injected,

Spring: register advice programmatically at runtime

天涯浪子 提交于 2019-12-04 13:10:29
Is it possible to register AOP advices programmatically, after the application has booted and the context has been initialized? When I tried, the advices didn't work, supposedly because they need to wrap the bean BEFORE it gets available in the context. Something like this (it doesn't work): @Bean private AspectJExpressionPointcutAdvisor createPointcutAdvisor(AWSXRayRecorder awsxRayRecorder, String name, String pointcut) { AspectJExpressionPointcutAdvisor advisor = new AspectJExpressionPointcutAdvisor(); advisor.setExpression("execution ...()"); advisor.setAdvice(new CustomAdvice("custom bean"

How to re-throw exception in AspectJ around advise

人盡茶涼 提交于 2019-12-04 12:51:36
问题 I have some methods which throws some exception, and I want to use AspectJ around advise to calculate the execution time and if some exception is thrown and to log into error log and continue the flow by re-throwing the exception. I tried to achieve this by following but eclipse says "Unhandled Exception type". Code-against whom aspectj is to used :- public interface Iface { public void reload() throws TException; public TUser getUserFromUserId(int userId, String serverId) throws