Apache Tomcat 8 spring加载时编织对ContextLoaderListener加载的bean不起作用

时间:2015-11-20 09:38:17

标签: java spring spring-mvc tomcat

从tomcat 7 java 7迁移到tomcat 8 java 8时出现问题。

在Tomcat 7中,加载时间编织基于context.xml文件中指定的加载器类

<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/> 

作为迁移的一部分,我们从context.xml中删除了上面的loader类定义,并将应用程序部署到tomcat8。

现在加载时间编织仅适用于由调度程序servlet加载的bean 并且ContextLoaderListener加载的applicationContext.xml中的 bean无法正常工作?请提供任何建议。

再次重复同样的问题..

如何在开始加载时间编织之前阻止applicationContext.xml中的bean 加载

尝试配置加载时间weaver而没有-javaagent选项是否可能

请注意以下配置的重要部分

的applicationContext.xml

<aop:aspectj-autoproxy />
    <context:spring-configured />
    <context:load-time-weaver aspectj-weaving="autodetect"/>     
    <tx:annotation-driven transaction-manager="transactionManager" mode="aspectj"/>

    <bean id="mainContextLoadingService"
          class="com.riyaskt.trial.service.impl.MainContextLoadingServiceImpl" />  

调度-servlet.xml中

<context:component-scan base-package="com.riyaskt.trial" />  
    <mvc:annotation-driven/>
<bean id="sampleService"
          class="com.riyaskt.trial.service.impl.SampleServiceImpl"          
          p:dao-ref="sampleDao"/> 

在这两个服务bean中(即applicationContext.xml中的 mainContextLoadingService 调度程序servlet 中的 sampleService )。

sampleService正确编织

但是

加载时间weaver

mainContextLoadingService 未编织 ..

2 个答案:

答案 0 :(得分:0)

试试Spring Instrument Jar。从link下载最新的4.2.3 jar。 在eclipse中打开tomcat的启动配置(在服务器选项卡中双击tomcat,然后单击打开启动配置)。现在点击参数标签,并将以下行添加到 VM参数

-javaagent:<Path to Spring Instrument jar you downloaded>

例如你下载了spring-instrument-4.2.3.RELEASE.jar并放入D盘,然后javaagent参数将如下:

-javaagent:D:\spring-instrument-4.2.3.RELEASE.jar

答案 1 :(得分:0)

使用aspectj-weaving =“autodetect”属性,如果类路径中存在“META-INF / aop.xml”资源,则默认激活AspectJ编织。