Spring Download AOP Download Boot Time

Not sure what is going wrong, but AOP just doesn't work in my setup using spring boot (v1.1.6).

@Configuration @ComponentScan @EnableJpaRepositories @EnableTransactionManagement @EnableAutoConfiguration @EnableCaching @EnableLoadTimeWeaving public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 

And in the classroom aspect

 @Aspect public class MyAspect { @AfterReturning(pointcut = "execution(private * com.myapp.service.MyService.test(..)) && args(str1,str2)", argNames = "str1,str2") public void advice(String str1, String str2) throws IOException { System.out.println("Advising after returning"); } } 

In a service class that needs advice

 @Service public class MyService { public void test(String str1, String str2) throws IOException { System.out.println("Test method in service"); //rest of the implementation } } 

I also have META-INF / aop.xml so that

 <!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"> <aspectj> <weaver> <!-- only weave classes in our application-specific packages --> <include within="com.myapp.*"/> </weaver> <aspects> <!-- weave in just this aspect --> <aspect name="com.myapp.aspect.MyAspect"/> </aspects> </aspectj> 

When I run the application using -javaagent: path / to / spring -instrument-4.1.0.RELEASE.jar

I get this message on the console

 2014-09-05 08:42:12.500 INFO 65053 --- [ main] oswshandler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] [ AppClassLoader@58644d46 ] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified 2014-09-05 08:42:13.114 INFO 65053 --- [ main] osjeaAnnotationMBeanExporter : Registering beans for JMX exposure on startup 2014-09-05 08:42:13.156 INFO 65053 --- [ main] osbaejmx.EndpointMBeanExporter : Registering beans for JMX exposure on startup [ AppClassLoader@58644d46 ] error can't determine implemented interfaces of missing type org.springframework.security.config.http.SessionCreationPolicy when weaving type org.springframework.boot.actuate.autoconfigure.ManagementServerProperties$Security when weaving classes when weaving [Xlint:cantFindType] [ AppClassLoader@58644d46 ] error can't determine implemented interfaces of missing type org.springframework.security.config.http.SessionCreationPolicy when weaving type org.springframework.boot.actuate.autoconfigure.ManagementServerProperties$Security when weaving classes when weaving [Xlint:cantFindType] 

However, nothing works with advice. It does not work.

Am I doing something wrong?

+5
source share
2 answers

In order to advise private methods, you need to use the privileged aspect:

 public privileged aspect MyAspect { // ... } 

But the AspectJ Documentation says:

Limitations: Privileged aspects are not supported by the annotation style.

Therefore, please use your own syntax, not the @AspectJ style. However, before you do this, check to see if the unprivileged aspects of the annotation style are exposed, as expected, using publicly available methods to rule out other reasons for interweaving your aspects.

0
source

I had the same problem. In my case, I had to annotate my aspect class using the @Component annotation.

  @Aspect @Component public class MyAspect { ... } 

The following link has a spring AOP boot example that helped me

https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-aop

0
source

Source: https://habr.com/ru/post/1201921/


All Articles