Skip to content

Commit 37f74e7

Browse files
committed
TomcatInstrumentableClassLoader supports Tomcat 7.0.63+ as well
Issue: SPR-13210
1 parent f4f508d commit 37f74e7

File tree

4 files changed

+63
-8
lines changed

4 files changed

+63
-8
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ project("spring-instrument-tomcat") {
448448
dependencies {
449449
provided("org.apache.tomcat:catalina:6.0.16")
450450
}
451+
452+
jar {
453+
exclude("org/apache/**") // exclude the mock used to bridge between pre-7.0.63 and 7.0.63+
454+
}
451455
}
452456

453457
project("spring-context") {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2002-2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.apache.catalina.loader;
18+
19+
/**
20+
* A mock of Tomcat's {@code WebappClassLoader} just for Spring's compilation purposes.
21+
* Exposes both pre-7.0.63 as well as 7.0.63+ variants of {@code findResourceInternal}.
22+
*
23+
* @author Juergen Hoeller
24+
* @since 4.2
25+
*/
26+
public class WebappClassLoader extends ClassLoader {
27+
28+
public WebappClassLoader() {
29+
}
30+
31+
public WebappClassLoader(ClassLoader parent) {
32+
super(parent);
33+
}
34+
35+
36+
protected ResourceEntry findResourceInternal(String name, String path) {
37+
throw new UnsupportedOperationException();
38+
}
39+
40+
protected ResourceEntry findResourceInternal(String name, String path, boolean manifestRequired) {
41+
throw new UnsupportedOperationException();
42+
}
43+
44+
}

spring-instrument-tomcat/src/main/java/org/springframework/instrument/classloading/tomcat/TomcatInstrumentableClassLoader.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* in the LoadTimeWeaver interface, as expected by ReflectiveLoadTimeWeaver.
4545
*
4646
* <p><b>NOTE:</b> Requires Apache Tomcat version 6.0 or higher, as of Spring 4.0.
47-
* This class does not work on Tomcat 7.0.63 and higher; please rely on Tomcat's own
47+
* This class is not intended to work on Tomcat 8.0+; please rely on Tomcat's own
4848
* {@code InstrumentableClassLoader} facility instead, as autodetected by Spring's
4949
* {@link org.springframework.instrument.classloading.tomcat.TomcatLoadTimeWeaver}.
5050
*
@@ -109,7 +109,7 @@ public ClassLoader getThrowawayClassLoader() {
109109
}
110110

111111

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

122+
@Override // overriding the 7.0.63+ variant of findResourceInternal
123+
protected ResourceEntry findResourceInternal(String name, String path, boolean manifestRequired) {
124+
ResourceEntry entry = super.findResourceInternal(name, path, manifestRequired);
125+
if (entry != null && entry.binaryContent != null && path.endsWith(CLASS_SUFFIX)) {
126+
String className = (name.endsWith(CLASS_SUFFIX) ? name.substring(0, name.length() - CLASS_SUFFIX.length()) : name);
127+
entry.binaryContent = this.weavingTransformer.transformIfNecessary(className, entry.binaryContent);
128+
}
129+
return entry;
130+
}
131+
122132
@Override
123133
public String toString() {
124-
StringBuilder sb = new StringBuilder(getClass().getName());
125-
sb.append("\r\n").append(super.toString());
126-
return sb.toString();
134+
return getClass().getName() + "\r\n" + super.toString();
127135
}
128136

129137

src/asciidoc/core-aop.adoc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,10 +3451,9 @@ Tomcat 6.0 and above.
34513451

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

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

0 commit comments

Comments
 (0)