diff --git a/spring-context/src/main/java/org/springframework/context/weaving/DefaultContextLoadTimeWeaver.java b/spring-context/src/main/java/org/springframework/context/weaving/DefaultContextLoadTimeWeaver.java index c5a7305052e..350e0b30ecf 100644 --- a/spring-context/src/main/java/org/springframework/context/weaving/DefaultContextLoadTimeWeaver.java +++ b/spring-context/src/main/java/org/springframework/context/weaving/DefaultContextLoadTimeWeaver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -47,7 +47,7 @@ import org.springframework.util.Assert; * appropriate weaver implementation: As of Spring Framework 5.0, it detects * Oracle WebLogic 10+, GlassFish 4+, Tomcat 8+, WildFly 8+, IBM WebSphere 8.5+, * {@link InstrumentationSavingAgent Spring's VM agent}, and any {@link ClassLoader} - * supported by Spring's {@link ReflectiveLoadTimeWeaver}. + * supported by Spring's {@link ReflectiveLoadTimeWeaver} (such as Liberty's). * * @author Juergen Hoeller * @author Ramnivas Laddad @@ -104,32 +104,29 @@ public class DefaultContextLoadTimeWeaver implements LoadTimeWeaver, BeanClassLo * This method never fails, allowing to try other possible ways to use an * server-agnostic weaver. This non-failure logic is required since * determining a load-time weaver based on the ClassLoader name alone may - * legitimately fail due to other mismatches. Specific case in point: the - * use of WebLogicLoadTimeWeaver works for WLS 10 but fails due to the lack - * of a specific method (addInstanceClassPreProcessor) for any earlier - * versions even though the ClassLoader name is the same. + * legitimately fail due to other mismatches. */ @Nullable protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) { String name = classLoader.getClass().getName(); try { - if (name.startsWith("weblogic")) { - return new WebLogicLoadTimeWeaver(classLoader); + if (name.startsWith("org.apache.catalina")) { + return new TomcatLoadTimeWeaver(classLoader); } else if (name.startsWith("org.glassfish")) { return new GlassFishLoadTimeWeaver(classLoader); } - else if (name.startsWith("org.apache.catalina")) { - return new TomcatLoadTimeWeaver(classLoader); - } - else if (name.startsWith("org.jboss")) { + else if (name.startsWith("org.jboss.modules")) { return new JBossLoadTimeWeaver(classLoader); } - else if (name.startsWith("com.ibm")) { + else if (name.startsWith("com.ibm.ws.classloader")) { return new WebSphereLoadTimeWeaver(classLoader); } + else if (name.startsWith("weblogic")) { + return new WebLogicLoadTimeWeaver(classLoader); + } } - catch (IllegalStateException ex) { + catch (Exception ex) { if (logger.isInfoEnabled()) { logger.info("Could not obtain server-specific LoadTimeWeaver: " + ex.getMessage()); } diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/weblogic/WebLogicClassLoaderAdapter.java b/spring-context/src/main/java/org/springframework/instrument/classloading/weblogic/WebLogicClassLoaderAdapter.java index 7a2a74afda5..1c49a44e67f 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/weblogic/WebLogicClassLoaderAdapter.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/weblogic/WebLogicClassLoaderAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -70,6 +70,7 @@ class WebLogicClassLoaderAdapter { throw new IllegalStateException( "Could not initialize WebLogic LoadTimeWeaver because WebLogic 10 API classes are not available", ex); } + if (!wlGenericClassLoaderClass.isInstance(classLoader)) { throw new IllegalArgumentException( "ClassLoader must be an instance of [" + wlGenericClassLoaderClass.getName() + "]: " + classLoader); diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereClassLoaderAdapter.java b/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereClassLoaderAdapter.java index f6aeaacc5cf..4334de848fa 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereClassLoaderAdapter.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/websphere/WebSphereClassLoaderAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -74,7 +74,8 @@ class WebSphereClassLoaderAdapter { } if (!wsCompoundClassLoaderClass.isInstance(classLoader)) { - throw new IllegalArgumentException("ClassLoader must be instance of " + COMPOUND_CLASS_LOADER_NAME); + throw new IllegalArgumentException( + "ClassLoader must be an instance of [" + COMPOUND_CLASS_LOADER_NAME + "]: " + classLoader); } this.classLoader = classLoader; }