You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TomcatInstrumentableClassLoader should support Tomcat 7.0.63+ as well [SPR-13210] #17802
This is not easy to fix since we can't properly call superclass methods reflectively... and we need to remain compatible with Tomcat 6.0+ still.
That said, Tomcat 7.0.44+ has a new InstrumentableClassLoader facility which we support as of Spring 4.0 already. All that it takes is <context:load-time-weaver> / @EnableLoadTimeWeaving which automatically registers a TomcatLoadTimeWeaver in case of Tomcat.
That native facility should work fine on Tomcat 7.0.63+ as well. So I recommend to simply drop your custom TomcatInstrumentableClassLoader definition and let Spring figure out how to use Tomcat's native InstrumentableClassLoader. If that doesn't work for you for some reason, let me know.
In any case, we should a note on this to the reference documentation, so I'm turning this into a documentation task.
Unfortunately, as far as I can tell, that patch was never backported into Tomcat 7.0.44 despite what the title says. InstrumentableClassLoader only exists in Tomcat 8.0+.
I ended up going back to Tomcat 7.0.62 for now. Using -javaagent with spring-instrument is of course also a workaround.
Ouch, even Tomcat's javadoc is wrong then, since it explicitly declares 7.0.44 there. I only ever tried this against Tomcat 8 and just assumed it would be there in 7.0.44+ as well :-(
We're compiling our TomcatInstrumentableClassLoader against a mock of Tomcat's WebappClassLoader now, allowing us to declare and override both versions of findResourceInternal... so that when bound to a real Tomcat WebappClassLoader at runtime, we'll override both the pre-7.0.63 and the 7.0.63+ variant of that method.
I've just noticed that LTW doesn't work properly when switching from 8.0.22 to 8.0.24 :(
Any chance this issue could apply in my case too?
I don't see any errors, just that the aspect doesn't get woven somehow.
This might indeed be related, since I suppose that the same change has been made in the Tomcat 8 line. The same fix, coming in 4.2 RC3, should also work on Tomcat 8 then.
However, are you still using Spring's TomcatInstrumentableClassLoader with Tomcat 8 to begin with? With TomcatLoadTimeWeaver, auto-selected by Spring when running on Tomcat, you should be able to rely on Tomcat 8's native instrumentation capabilities...
I've started to investigate the issue since it was failing with TomcatLoadTimeWeaver on 8.0.22.
As far as I see, the only combination that worked was with TomcatInstrumentableClassLoader on 8.0.22.
On 8.0.24 both options fail.
The latest 4.2.0.BUILD-SNAPSHOT already comes with a spring-instrument-tomcat variant that should work on Tomcat 7.0.63 / 8.0.24 as well... Would be great if you could give it an early try, just grabbing it from http://repo.spring.io/snapshot. We'll release it tonight in 4.2 RC3 then.
I'm surprised that TomcatLoadTimeWeaver doesn't work for you though? In which way does it fail?
Hmm, it looks like Tomcat's own instrumentable class loader selectively applies the weaving to application classes only there. I'm afraid we cannot do much about this from Spring's side; you'd really have to report that part to Tomcat itself. Our TomcatLoadTimeWeaver does nothing more than pass transformer handles to Tomcat's class loader, after all.
As for our own TomcatInstrumentableClassLoader, any chance that the latest 4.2 snapshot works for you there?
Yes, it works with the TomcatInstrumentableClassLoader from 4.2.0 SNAPSHOT.
Would have been nice to have it work with TomcatLoadTimeWeaver as the virtual host setup we want doesn't seem to load the context.xml from the web app :(
As for TomcatLoadTimeWeaver, that's definitely preferrred on Tomcat 8. No idea why you're seeing that limitation; please do raise it with the Tomcat team.
I've created https://bz.apache.org/bugzilla/show_bug.cgi?id=58143
As far as I see, when the application gets deployed, Tomcat tries to discover various classes to process servlet annotations.
The resources for these classes get cached in WebappClassLoaderBase.resourceEntries before the Spring Framework is started, so any calls to WebappClassLoaderBase.findResourceInternal will return the cached resources and the transformers will not be run.
A workaround could be for TomcatLoadTimeWeaver.addTransformer to clear the resourceEntries map.
I have reopened the Tomcat ticket regarding registration of transformers suggesting an alternative mechanism for discovering transformers via something like ServiceLoader.
Activity
spring-projects-issues commentedon Jul 7, 2015
Juergen Hoeller commented
This is not easy to fix since we can't properly call superclass methods reflectively... and we need to remain compatible with Tomcat 6.0+ still.
That said, Tomcat 7.0.44+ has a new InstrumentableClassLoader facility which we support as of Spring 4.0 already. All that it takes is
<context:load-time-weaver>/@EnableLoadTimeWeavingwhich automatically registers aTomcatLoadTimeWeaverin case of Tomcat.That native facility should work fine on Tomcat 7.0.63+ as well. So I recommend to simply drop your custom
TomcatInstrumentableClassLoaderdefinition and let Spring figure out how to use Tomcat's nativeInstrumentableClassLoader. If that doesn't work for you for some reason, let me know.In any case, we should a note on this to the reference documentation, so I'm turning this into a documentation task.
Juergen
spring-projects-issues commentedon Jul 7, 2015
Juergen Hoeller commented
I've added explicit notes for load-time weaving on Tomcat 7.0.63+ and WildFly 9 to the reference documentation.
Juergen
spring-projects-issues commentedon Jul 7, 2015
Emil Lundström commented
I think you are referring to #15414, and the corresponding issue in Tomcat's issue tracker: https://bz.apache.org/bugzilla/show_bug.cgi?id=55317
Unfortunately, as far as I can tell, that patch was never backported into Tomcat 7.0.44 despite what the title says. InstrumentableClassLoader only exists in Tomcat 8.0+.
I ended up going back to Tomcat 7.0.62 for now. Using -javaagent with spring-instrument is of course also a workaround.
spring-projects-issues commentedon Jul 7, 2015
Juergen Hoeller commented
Ouch, even Tomcat's javadoc is wrong then, since it explicitly declares 7.0.44 there. I only ever tried this against Tomcat 8 and just assumed it would be there in 7.0.44+ as well :-(
Here's the Tomcat change that led to the change in
findResourceInternal's signature:https://bz.apache.org/bugzilla/show_bug.cgi?id=58023
Let's see what we can do about this, also involving Mark Thomas from the Tomcat team who was certainly not aware of the implications of this change...
spring-projects-issues commentedon Jul 13, 2015
Juergen Hoeller commented
We're compiling our
TomcatInstrumentableClassLoaderagainst a mock of Tomcat'sWebappClassLoadernow, allowing us to declare and override both versions offindResourceInternal... so that when bound to a real TomcatWebappClassLoaderat runtime, we'll override both the pre-7.0.63 and the 7.0.63+ variant of that method.Juergen
spring-projects-issues commentedon Jul 14, 2015
Andrei Ivanov commented
I've just noticed that LTW doesn't work properly when switching from 8.0.22 to 8.0.24 :(
Any chance this issue could apply in my case too?
I don't see any errors, just that the aspect doesn't get woven somehow.
spring-projects-issues commentedon Jul 14, 2015
Juergen Hoeller commented
This might indeed be related, since I suppose that the same change has been made in the Tomcat 8 line. The same fix, coming in 4.2 RC3, should also work on Tomcat 8 then.
However, are you still using Spring's
TomcatInstrumentableClassLoaderwith Tomcat 8 to begin with? WithTomcatLoadTimeWeaver, auto-selected by Spring when running on Tomcat, you should be able to rely on Tomcat 8's native instrumentation capabilities...Juergen
spring-projects-issues commentedon Jul 15, 2015
Andrei Ivanov commented
I've started to investigate the issue since it was failing with
TomcatLoadTimeWeaveron 8.0.22.As far as I see, the only combination that worked was with
TomcatInstrumentableClassLoaderon 8.0.22.On 8.0.24 both options fail.
spring-projects-issues commentedon Jul 15, 2015
Juergen Hoeller commented
The latest
4.2.0.BUILD-SNAPSHOTalready comes with aspring-instrument-tomcatvariant that should work on Tomcat 7.0.63 / 8.0.24 as well... Would be great if you could give it an early try, just grabbing it fromhttp://repo.spring.io/snapshot. We'll release it tonight in 4.2 RC3 then.I'm surprised that
TomcatLoadTimeWeaverdoesn't work for you though? In which way does it fail?Juergen
spring-projects-issues commentedon Jul 15, 2015
Andrei Ivanov commented
Using
TomcatLoadTimeWeaver, theExporterclass is not being passed throughWeavingTransformer.transformIfNecessary, only the children.Using
TomcatInstrumentableClassLoader, the parent class gets transformed:typeToWeave = org.primefaces.component.export.ExcelExporter
typeToWeave = org.primefaces.component.export.Exporter
spring-projects-issues commentedon Jul 15, 2015
Juergen Hoeller commented
Hmm, it looks like Tomcat's own instrumentable class loader selectively applies the weaving to application classes only there. I'm afraid we cannot do much about this from Spring's side; you'd really have to report that part to Tomcat itself. Our
TomcatLoadTimeWeaverdoes nothing more than pass transformer handles to Tomcat's class loader, after all.As for our own
TomcatInstrumentableClassLoader, any chance that the latest 4.2 snapshot works for you there?Juergen
spring-projects-issues commentedon Jul 15, 2015
Andrei Ivanov commented
Yes, it works with the
TomcatInstrumentableClassLoaderfrom 4.2.0 SNAPSHOT.Would have been nice to have it work with
TomcatLoadTimeWeaveras the virtual host setup we want doesn't seem to load thecontext.xmlfrom the web app :(spring-projects-issues commentedon Jul 15, 2015
Juergen Hoeller commented
Great to hear, thanks for the timely feedback!
As for
TomcatLoadTimeWeaver, that's definitely preferrred on Tomcat 8. No idea why you're seeing that limitation; please do raise it with the Tomcat team.Juergen
spring-projects-issues commentedon Jul 15, 2015
Andrei Ivanov commented
I've created https://bz.apache.org/bugzilla/show_bug.cgi?id=58143
As far as I see, when the application gets deployed, Tomcat tries to discover various classes to process servlet annotations.
The resources for these classes get cached in
WebappClassLoaderBase.resourceEntriesbefore the Spring Framework is started, so any calls toWebappClassLoaderBase.findResourceInternalwill return the cached resources and the transformers will not be run.A workaround could be for
TomcatLoadTimeWeaver.addTransformerto clear theresourceEntriesmap.spring-projects-issues commentedon Jul 20, 2015
Andrei Ivanov commented
Jurgen,
Can I direct your attention to the Tomcat ticket I've created?
They've added a comment and I think it might be best if you could chime in.
spring-projects-issues commentedon Jul 24, 2015
Andrei Ivanov commented
Juergen Hoeller?
spring-projects-issues commentedon Sep 4, 2015
Bryn Cooke commented
I have reopened the Tomcat ticket regarding registration of transformers suggesting an alternative mechanism for discovering transformers via something like ServiceLoader.
https://bz.apache.org/bugzilla/show_bug.cgi?id=58143
It would be great if the spring could share their views on if it is a good idea or otherwise.