2014-09-05 13 views
5

Non sono sicuro di ciò che sta andando storto, ma AOP non sembra funzionare correttamente nella mia configurazione con avvio a molla (v1.1.6).Spring Boot AOP tempo di caricamento tessitura

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

E nella classe aspetto

@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"); 
    } 
} 

Nella classe di servizio che ha bisogno il consiglio

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

Ho anche un META-INF/aop.xml in questo modo

<!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> 

Quando eseguo l'applicazione con -ja vaagent: path/to/primavera-strumento-4.1.0.RELEASE.jar

ottengo questo messaggio sulla console

2014-09-05 08:42:12.500 INFO 65053 --- [   main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 
[[email protected]] 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] o.s.j.e.a.AnnotationMBeanExporter  : Registering beans for JMX exposure on startup 
2014-09-05 08:42:13.156 INFO 65053 --- [   main] o.s.b.a.e.jmx.EndpointMBeanExporter  : Registering beans for JMX exposure on startup 
[[email protected]] 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] 
[[email protected]] 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] 

Nulla accade con la consulenza però. Non sparerà.

Sto facendo qualcosa di sbagliato?

risposta

0

Al fine di consigliare metodi privati ​​è necessario utilizzare un privilegiata aspetto:

public privileged aspect MyAspect { 
    // ... 
} 

Ma la AspectJ documentation dice:

Limitazioni: aspetti privilegiati non sono supportati da lo stile di annotazione.

Quindi utilizzare la sintassi nativa, non lo stile @spectJ. Prima di farlo, però, prova se gli aspetti in stile annotazione non privilegiati funzionano come previsto con i metodi pubblici, al fine di escludere altri motivi per cui i tuoi aspetti vengono intrecciati.