【问题标题】:Apache Tomcat 8 spring load time weaving is not working for beans loaded by ContextLoaderListenerApache Tomcat 8 春季加载时间编织不适用于 ContextLoaderListener 加载的 bean
【发布时间】:2016-02-22 17:50:21
【问题描述】:

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

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

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

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

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

再次重复同一个问题..

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

我正在尝试在没有 -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" />  

dispatcher-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 中的 ma​​inContextLoadingServicedispatcher servlet 中的 sampleService)。

sampleService 编织得当

但是

mainContextLoadingService 没有被加载时间编织器编织..

【问题讨论】:

  • 打开 org.springframework 的调试日志并检查是否在删除 tomcat 加载程序时遇到任何错误。如果是,请编辑您的主要帖子并将其添加到那里。

标签: java spring spring-mvc tomcat


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    试试 Spring Instrument Jar。从此link 下载最新的 4.2.3 jar。 在 Eclipse 中打开您的 tomcat 的启动配置(在 Servers 选项卡中双击您的 tomcat 并点击 Open launch configuration)。现在点击 Arguments 选项卡并将以下行附加到 VM arguments

    -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
    

    【讨论】:

    • 我正在尝试在没有 -javaagent 选项的情况下配置加载时间编织器。
    • 如何配置每个类加载器的加载时间编织器?不适用于整个 jvm。
    • 当前编织正在工作,没有 -javaagent 到调度程序 servlet 加载本
    • 我正在尝试一个没有 -javaagent 的解决方案。
    • 我也尝试使用 -javaagent 但现在调度程序 servlet 加载的 bean 无法获取应用程序上下文加载的 bean 的引用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多