我正在使用最新的springboot v1.5.2与aspectj(v1.8.10)加载时间编织 . 在外部tomcat上运行我的应用程序时,我能够将spring bean注入我的aspectj方面,现在我想知道为什么嵌入式tomcat的同样失败了?
springboot: 1.5.2
Aspectj: 1.8.10
spring 仪表: 4.3.7.RELEASE
maven命令: mvn spring-boot:run -Drun.jvmArguments=" -javaagent:aspectjweaver-1.8.10.jar -javaagent:spring-instrument-4.3.7.RELEASE.jar -Dserver.port=8080 -Dserver.contextPath=/custom-application"
方面配置:
@Configuration
@EnableLoadTimeWeaving
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class AspectConfig {
@Bean
public RuntimeContainerDelegateAspect runtimeContainerDelegateAspect() {
return Aspects.aspectOf(RuntimeContainerDelegateAspect.class);
}}
方面:
@Aspect
public class RuntimeContainerDelegateAspect {
private static final Logger LOGGER = LoggerFactory.getLogger(RuntimeContainerDelegateAspect.class);
@Autowired
private RestApplicationDeployer deployer;
@Pointcut("execution(* org.someapp.container.impl.RuntimeContainerDelegateImpl.deployApplication(..))")
public void deployApplication() {
}
@Pointcut("execution(* org.someapp.container.impl.RuntimeContainerDelegateImpl.undeployProcessApplication(..))")
public void undeployApplication() {
}
@Around("deployApplication()")
public void aroundDeploy(ProceedingJoinPoint pjp) throws Throwable {
if (LOGGER.isInfoEnabled())
LOGGER.info("RuntimeDelegateCalled: " + pjp.toString());
AbstractProcessApplication app = (AbstractProcessApplication) pjp.getArgs()[0];
LOGGER.debug("deployer={}", deployer);
deployer.deploy(app);
}
@Around("undeployApplication()")
public void aroundUndeploy(ProceedingJoinPoint pjp) throws Throwable {
if (LOGGER.isInfoEnabled())
LOGGER.info("RuntimeDelegateCalled: " + pjp.toString() + "\n" +
"Default implementation does nothing.");
}
}
部署:
@Component
public class RestApplicationDeployer {
//it's just an ordinary spring bean
}
实际结果: deployer = null, since aspectj creates new instance of the RuntimeContainerDelegateAspect for processing @Around advice
预期结果:deployer = spring bean RestApplicationDeployer
P.S: This works perfectly on an external tomcat instance