aspectj

Why server complaining about aspectOf is missing?

邮差的信 提交于 2019-12-22 04:54:06
问题 I am currently trying to inject Spring bean in AspectJ like the code shown below, anyhow I the server (WAS Liberty Profile) keep complaining the method aspectOf is missing. May I know how could I solve this problem? application-context.xml <aop:aspectj-autoproxy/> <import resource="/context-file-A.xml"/> context-file-A.xml <bean id="loggingAspect" class="com.huahsin.LoggingAspect" factory-method="aspectOf"> JAVA code @Aspect public class LoggingAspect { ... } 回答1: This is a common error when

AspectJ Maven Plugin cannot compile my project

半世苍凉 提交于 2019-12-22 02:47:08
问题 I try to use aspectj maven plugin for compile project with aspectj compiler and then I try to package classes into "war" file. Unfortunately, it doesn't work with following configuration (pom.xml): <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.17</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <plugin> <groupId>com.liferay.maven.plugins</groupId> <artifactId>liferay-maven-plugin

AspectJ not capture calls from jar file

倖福魔咒の 提交于 2019-12-22 00:41:55
问题 I want to do specific action when System.currentTimeMillis() is called. I use AspectJ as below to do that. public aspect CurrentTimeInMillisMethodCallChanger { long around(): call(public static native long java.lang.System.currentTimeMillis()) { //provide my own implementation } } This program works fine when System.currentTimeMillis() is called in any method of the application. However, when System.currentTimeMillis() is called from method inside a jar file then around is not executed. I

Applying @PostFilter annotation to a generic Spring Data Jpa repository method

邮差的信 提交于 2019-12-22 00:34:40
问题 I want to use the @PostFilter annotation on a Spring Data Jpa repository generic method (such as a findAll ) as follows: @PostFilter("filterObject.isActivated()==true") public List<Advertisement> findAll(); How can I do that bearing in mind the those methods are provided "automagically" by Spring Data Jpa and are therefore not exposed in the application code? 回答1: Yes, you can add a @PostFilter to any method provided by a Spring Data Repository. Just override existing method findAll() and add

Check if aspectjweaver (or any javaagent) is loaded

我只是一个虾纸丫 提交于 2019-12-22 00:09:13
问题 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). 回答1: 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

AspectJ constructor force factory pattern

纵饮孤独 提交于 2019-12-21 21:33:45
问题 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(

AspectJ Pointcut on Methods with Multiple Annotations

拟墨画扇 提交于 2019-12-21 21:17:00
问题 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

APT and AOP in the same project, using Maven

浪尽此生 提交于 2019-12-21 20:28:47
问题 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

@Around @Aspect in the same package only works with @DependsOn

蓝咒 提交于 2019-12-21 20:12:04
问题 Please see the updates below. I have a Spring Boot application where I accept TCP/IP connections: public MyClass implements InitializingBean { @Override public void afterPropertiesSet() throws Exception { try (ServerSocket serverSocket = new ServerSocket(port)) { while (true) { Socket socket = serverSocket.accept(); new ServerThread(socket).start(); } } } ... private class ServerThread extends Thread { @Override public void run() { try (InputStream input = socket.getInputStream();

How to override ant task stored in ant lib directory

冷暖自知 提交于 2019-12-21 19:53:50
问题 At my work we use AspectJ in some of our Java projects. To get this to work with ant builds we have been placing aspectjtools.jar within ant/lib/. I am now working on a particular Java project and need to use a newer version of aspectJ. I don't want to have to get everyone who uses the project to update their local copy of aspectjtools.jar. Instead, I tried adding the newer aspectjtools.jar to the lib directory of the project and adding the following line to build.xml. <taskdef resource="org