1

我正在使用最近的 springboot v1.5.2 和 aspectj(v1.8.10)的加载时间编织。在外部 tomcat 上运行我的应用程序时,我能够将 spring bean 注入到我的 aspectj 方面,现在我想知道为什么嵌入式 tomcat 也失败了?

弹簧靴:1.5.2

方面:1.8.10

弹簧仪表: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= /自定义应用程序”

方面配置:

@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,因为 aspectj 创建了 RuntimeContainerDelegateAspect 的新实例来处理 @Around 通知

预期结果:deployer = spring bean RestApplicationDeployer

PS:这在外部 tomcat 实例上完美运行

4

0 回答 0