Skip to content

Commit

Permalink
TomcatInstrumentableClassLoader supports Tomcat 7.0.63+ as well
Browse files Browse the repository at this point in the history
Issue: SPR-13210
  • Loading branch information
jhoeller committed Jul 14, 2015
1 parent f4f508d commit 37f74e7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ project("spring-instrument-tomcat") {
dependencies {
provided("org.apache.tomcat:catalina:6.0.16")
}

jar {
exclude("org/apache/**") // exclude the mock used to bridge between pre-7.0.63 and 7.0.63+
}
}

project("spring-context") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.catalina.loader;

/**
* A mock of Tomcat's {@code WebappClassLoader} just for Spring's compilation purposes.
* Exposes both pre-7.0.63 as well as 7.0.63+ variants of {@code findResourceInternal}.
*
* @author Juergen Hoeller
* @since 4.2
*/
public class WebappClassLoader extends ClassLoader {

public WebappClassLoader() {
}

public WebappClassLoader(ClassLoader parent) {
super(parent);
}


protected ResourceEntry findResourceInternal(String name, String path) {
throw new UnsupportedOperationException();
}

protected ResourceEntry findResourceInternal(String name, String path, boolean manifestRequired) {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* in the LoadTimeWeaver interface, as expected by ReflectiveLoadTimeWeaver.
*
* <p><b>NOTE:</b> Requires Apache Tomcat version 6.0 or higher, as of Spring 4.0.
* This class does not work on Tomcat 7.0.63 and higher; please rely on Tomcat's own
* This class is not intended to work on Tomcat 8.0+; please rely on Tomcat's own
* {@code InstrumentableClassLoader} facility instead, as autodetected by Spring's
* {@link org.springframework.instrument.classloading.tomcat.TomcatLoadTimeWeaver}.
*
Expand Down Expand Up @@ -109,7 +109,7 @@ public ClassLoader getThrowawayClassLoader() {
}


@Override
@Override // overriding the pre-7.0.63 variant of findResourceInternal
protected ResourceEntry findResourceInternal(String name, String path) {
ResourceEntry entry = super.findResourceInternal(name, path);
if (entry != null && entry.binaryContent != null && path.endsWith(CLASS_SUFFIX)) {
Expand All @@ -119,11 +119,19 @@ protected ResourceEntry findResourceInternal(String name, String path) {
return entry;
}

@Override // overriding the 7.0.63+ variant of findResourceInternal
protected ResourceEntry findResourceInternal(String name, String path, boolean manifestRequired) {
ResourceEntry entry = super.findResourceInternal(name, path, manifestRequired);
if (entry != null && entry.binaryContent != null && path.endsWith(CLASS_SUFFIX)) {
String className = (name.endsWith(CLASS_SUFFIX) ? name.substring(0, name.length() - CLASS_SUFFIX.length()) : name);
entry.binaryContent = this.weavingTransformer.transformIfNecessary(className, entry.binaryContent);
}
return entry;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder(getClass().getName());
sb.append("\r\n").append(super.toString());
return sb.toString();
return getClass().getName() + "\r\n" + super.toString();
}


Expand Down
5 changes: 2 additions & 3 deletions src/asciidoc/core-aop.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3451,10 +3451,9 @@ Tomcat 6.0 and above.

[TIP]
====
Do not define `TomcatInstrumentableClassLoader` anymore as of Tomcat 7.0.44+ / 8.0.
Do not define `TomcatInstrumentableClassLoader` anymore on Tomcat 8.0 and higher.
Instead, let Spring automatically use Tomcat's new native `InstrumentableClassLoader`
facility through the `TomcatLoadTimeWeaver` strategy, in particular on Tomcat 7.0.63+
where `TomcatInstrumentableClassLoader` does not work at all anymore.
facility through the `TomcatLoadTimeWeaver` strategy.
====

If you still need to use `TomcatInstrumentableClassLoader`, it can be registered
Expand Down

0 comments on commit 37f74e7

Please sign in to comment.