Skip to content

Commit d187cbc

Browse files
committed
LoadTimeWeaver detection differentiates between WebSphere and Liberty
Issue SPR-16248
1 parent 6a1fe0b commit d187cbc

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

spring-context/src/main/java/org/springframework/context/weaving/DefaultContextLoadTimeWeaver.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@
4747
* appropriate weaver implementation: As of Spring Framework 5.0, it detects
4848
* Oracle WebLogic 10+, GlassFish 4+, Tomcat 8+, WildFly 8+, IBM WebSphere 8.5+,
4949
* {@link InstrumentationSavingAgent Spring's VM agent}, and any {@link ClassLoader}
50-
* supported by Spring's {@link ReflectiveLoadTimeWeaver}.
50+
* supported by Spring's {@link ReflectiveLoadTimeWeaver} (such as Liberty's).
5151
*
5252
* @author Juergen Hoeller
5353
* @author Ramnivas Laddad
@@ -104,32 +104,29 @@ else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
104104
* This method never fails, allowing to try other possible ways to use an
105105
* server-agnostic weaver. This non-failure logic is required since
106106
* determining a load-time weaver based on the ClassLoader name alone may
107-
* legitimately fail due to other mismatches. Specific case in point: the
108-
* use of WebLogicLoadTimeWeaver works for WLS 10 but fails due to the lack
109-
* of a specific method (addInstanceClassPreProcessor) for any earlier
110-
* versions even though the ClassLoader name is the same.
107+
* legitimately fail due to other mismatches.
111108
*/
112109
@Nullable
113110
protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) {
114111
String name = classLoader.getClass().getName();
115112
try {
116-
if (name.startsWith("weblogic")) {
117-
return new WebLogicLoadTimeWeaver(classLoader);
113+
if (name.startsWith("org.apache.catalina")) {
114+
return new TomcatLoadTimeWeaver(classLoader);
118115
}
119116
else if (name.startsWith("org.glassfish")) {
120117
return new GlassFishLoadTimeWeaver(classLoader);
121118
}
122-
else if (name.startsWith("org.apache.catalina")) {
123-
return new TomcatLoadTimeWeaver(classLoader);
124-
}
125-
else if (name.startsWith("org.jboss")) {
119+
else if (name.startsWith("org.jboss.modules")) {
126120
return new JBossLoadTimeWeaver(classLoader);
127121
}
128-
else if (name.startsWith("com.ibm")) {
122+
else if (name.startsWith("com.ibm.ws.classloader")) {
129123
return new WebSphereLoadTimeWeaver(classLoader);
130124
}
125+
else if (name.startsWith("weblogic")) {
126+
return new WebLogicLoadTimeWeaver(classLoader);
127+
}
131128
}
132-
catch (IllegalStateException ex) {
129+
catch (Exception ex) {
133130
if (logger.isInfoEnabled()) {
134131
logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage());
135132
}

spring-context/src/main/java/org/springframework/instrument/classloading/weblogic/WebLogicClassLoaderAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,6 +70,7 @@ public WebLogicClassLoaderAdapter(ClassLoader classLoader) {
7070
throw new IllegalStateException(
7171
"Could not initialize WebLogic LoadTimeWeaver because WebLogic 10 API classes are not available", ex);
7272
}
73+
7374
if (!wlGenericClassLoaderClass.isInstance(classLoader)) {
7475
throw new IllegalArgumentException(
7576
"ClassLoader must be an instance of [" + wlGenericClassLoaderClass.getName() + "]: " + classLoader);

spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereClassLoaderAdapter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,7 +74,8 @@ public WebSphereClassLoaderAdapter(ClassLoader classLoader) {
7474
}
7575

7676
if (!wsCompoundClassLoaderClass.isInstance(classLoader)) {
77-
throw new IllegalArgumentException("ClassLoader must be instance of " + COMPOUND_CLASS_LOADER_NAME);
77+
throw new IllegalArgumentException(
78+
"ClassLoader must be an instance of [" + COMPOUND_CLASS_LOADER_NAME + "]: " + classLoader);
7879
}
7980
this.classLoader = classLoader;
8081
}

0 commit comments

Comments
 (0)