mercredi 4 mars 2015

Why AspectJ weaving on package scoped methods not working?

I am trying to print logs for private and package scoped methods (from package scoped classes) in my application which is based on Spring. Since Spring's proxy based aspects don't work on private and package scoped methods(?), I tried to use AspectJ load time weaving as per the documentation. Below are the details:


LoggingAspect



@Component(Constants.LOGGING_ASPECT_BEAN)
@Aspect
public class LoggingAspect {
@Around("@annotation(my.pkg.Loggable)")
public Object doLogging(final ProceedingJoinPoint joinPoint) throws Throwable {
// ... logging code.
}
}


Spring Configuration



@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@Import(AnotherBaseConfig.class)
@ComponentScan("my.pkg")
@EnableWebMvc
@EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.AUTODETECT)
public class AppConfiguration extends WebMvcConfigurerAdapter {
// ... bean configs
}


src/main/webapp/META-INF/aop.xml



<aspectj>
<weaver>
<include within="my.pkg.*">
</weaver>
<aspects>
<aspect name="my.logger.LoggingAspect"/>
</aspects>
</aspectj>


JVM Config



-javaagent:"/path/to/spring-instrument-4.0.6.jar" -javaagent:"/path/to/aspectjweaver-1.8.1.jar"


With above configurations, I have my package scoped classes as:



@Component("someClass")
class SomeClass {
@Loggable
void doSomething(@Loggable final String s, @Loggable final Integer i) {
// ... do something here.
}
}


The weaving is not working for such package scoped classes. Am I doing anything wrong?


Aucun commentaire:

Enregistrer un commentaire