在-javaagent下,Tomcat 6.0.44如何設置負載時間與Spring和Tomcat織,不許使用我使用Spring 3.2.9命令行
我想配置我的應用程序的Spring儀器提供商(例如spring-instrumentation.jar)用於加載時織入,當它被部署在Tomcat上時。
我有一個不使用的要求: 「-javaagent:/path/path/spring-instrument.jar」在命令行上進行配置。
我讀過我可以通過修改應用程序的Tomcat配置(在Tomcat的server.xml或我的web應用程序的context.xml中)的<Context>元素來配置Spring工具。將適當的<上下文>元素添加到server.xml導致我的應用程序被正確配置爲與Spring的工具提供程序一起運行。將它添加到context.xml(見下文)不會導致工作設置。
我有一個META-INF/aop.xml文件文件,如下所示:
<aspectj>
<weaver options="-verbose -showWeaveInfo -debug">
<include within="com.mv.xx.services..*"/>
<exclude within="com.mv.xx.aop..*"/>
</weaver>
<aspects>
<aspect name="com.mv.xx.aop.MyAspect"/>
</aspects>
</aspectj>
我還規定,我想加入這個我Spring上下文配置使用負載時編織:
<context:load-time-weaver />
我補充這個罈子我的應用程序的類路徑: 彈簧儀器tomcat.jar
我曾嘗試:
當啓動Tomcat,如果我確定使用-javaagent參數這樣的命令行上的彈簧instrument.jar的位置:
-javaagent:/path/path2/spring-instrument-3.2.9.RELEASE.jar
,一切工作正常。在命令行:
接着我刪除 「/path/path2/spring-instrument-3.2.9.RELEASE.jar -javaagent」。 在Tomcat的server.xml文件(位於$ CATALINE_HOME/conf目錄),我加了一個<上下文>元素的<主機>元素,像這樣:
<Context path="/myApp" docBase="myApp">
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
</Context>
利用這種配置的一切行爲正確。不過,我有一個要求,不要修改Tomcat的server.xml,因爲我無法控制server.xml(DevOps所做的並且不願修改它)。
接下來我刪除從Tomcat的server.xml中<語境>元素。 根據Spring docs,我可以將/META-INF/context.xml添加到我的webapp,並將原來在Tomcat的server.xml中的<Context>元素放入上下文中。XML,像這樣:
<Context>
<Context path="/myApp" docBase="myApp">
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
</Context>
</Context>
然而,當我重新啓動Tomcat,我獲取日誌中的一個錯誤消息說:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.weaving.AspectJWeavingEnabler#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
周圍挖掘後,我讀了一些建議我修改<context:load-time-weaver/>
元素在我的Spring配置中,像這樣:
<context:load-time-weaver weaver-class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
並將包含InstrumentationLoadTimeWeaver.class的jar添加到我的類路徑中。
然而,當我這樣做,我在日誌中收到此錯誤信息:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.
etc....
誰能解釋如何設置加載時間與Spring和Tomcat織不使用命令行-javaagent,並沒有修改server.xml?
同樣的問題!任何解決方案 – HVT7