如何使Tomcat与META-INF/context.xml中定义的TomcatInstrumentableClassLoader以及WEB-INF/lib/spring-instrument-Tomcat.jar一起工作

如何使Tomcat与META-INF/context.xml中定义的TomcatInstrumentableClassLoader以及WEB-INF/lib/spring-instrument-Tomcat.jar一起工作,tomcat,classloader,spring-data,load-time-weaving,context.xml,Tomcat,Classloader,Spring Data,Load Time Weaving,Context.xml,我构建了一个简单的应用程序,它在服务器端使用SpringData3.1.0.RELEASE和Eclipselink 2.4,托管在Tomcat7.0.27中。在mywebapp/META-INF/context.xml中,我有Spring类加载器 <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/> 上下文加载器参数useS

我构建了一个简单的应用程序,它在服务器端使用SpringData3.1.0.RELEASE和Eclipselink 2.4,托管在Tomcat7.0.27中。在mywebapp/META-INF/context.xml中,我有Spring类加载器

<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
上下文加载器参数
useSystemClassLoaderAsParent
设置为
false
也没有帮助


我不想在Tomcat中有任何(定制的)全局库(而且在我们的实际生产系统中有全局库并不容易),因此我试图将所有需要的东西本地化为简单(但很大)的war文件。关于如何实现这种封装有什么想法吗?

可能是您的
上下文。xml
不正确。试试这个:

<?xml version="1.0" encoding="UTF-8" ?>
<Context>
  <Loader
    loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"
    useSystemClassLoaderAsParent="false" />
</Context>


好吧,如果您不想在Tomcat的lib文件夹中有额外的jar,唯一的选择(仍然让Spring/AspectJ LTW工作)是编辑Tomcat的运行脚本,将-javaagent:…instrument.jar添加到其JAVA_OPTS或CATALINA_OPTS中,并删除context.xml文件(您不需要TomcatInstrumentableClassLoad)‌​

我尝试了你对useSystemClassLoaderAsParent的建议,但在Tomcat 7上我得到了
警告:[SetPropertiesRule]{Context/Loader}将属性“useSystemClassLoaderAsParent”设置为“false”没有找到匹配的属性。
而且,正如预期的那样,下一个错误是
java.lang.ClassNotFoundException:org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
。我也使用tomcat7,但我成功了。spring-instrument-tomcat.jar应该放在tomcat/lib中。我认为你放的位置不对。我说,我使用intellij的思想来开发,我把context.xml放在tomcat7utf8\conf\Catalina\localhost\yourwebappnameditory\这里,它完全是这样的:`` web应用不在tomcat\webapp目录中。好吧,如果我理解正确,你建议把tomcat-instrumental.jar放在tomcat/lib中,但这正是我不想做的(但目前我没有其他方法让它工作。我的问题是如何让Tomcat/lib保持不变,并用它自己的libs来满足我的应用程序。好吧,你不想向Tomcat添加任何内容。唯一的方法是你应该编辑Tomcat.startup.bat来添加以下内容(这是spring建议):-javaagent:E:/spring instrument.jar(可能在其他地方)spring-instrument.jar不是spring-instrument-tomcat.jar!并且不在其中保留context.xml。这种方法也可能有效。是的,几乎有一件事你必须做。你可以在tomcat中添加一些jar或修改启动脚本。这是spring和aspectj建议的方法,我认为你不会首先只使用aspectj编写类,所以这是唯一的方法。我有将您的答案视为正确答案,因为这是迄今为止找到的最佳解决方案。谢谢!
<?xml version="1.0" encoding="UTF-8" ?>
<Context>
  <Loader
    loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"
    useSystemClassLoaderAsParent="false" />
</Context>