public final class DevToolsClassLoaders extends java.lang.Object
Resolves the class loader GORM and Hibernate should use when Spring Boot DevTools restart is active.
DevTools splits the classpath across a base loader (third-party jars, including
GORM and Hibernate) and a RestartClassLoader (application classes). Hibernate's
JPA metamodel and GORM's entity registry key entities by java.lang.Class identity, so a
domain class Hibernate resolved through the base loader is "not an entity" to code
holding the restart loader's copy. Hibernate resolves entities by name through the
loader it is bootstrapped with, so that loader must see the restarted classes.
The thread context class loader is not always the RestartClassLoader itself
while the application starts. A servlet container swaps in its own web application
loader during context start (Tomcat's TomcatEmbeddedWebappClassLoader), and
that loader delegates to the RestartClassLoader as its parent. Every check here
therefore walks the parent chain rather than matching only the loader's own type.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static boolean |
isRestartClassLoader(java.lang.ClassLoader classLoader)
|
|
public static boolean |
isRestartClassLoaderOrDescendant(java.lang.ClassLoader classLoader)
|
|
public static java.lang.ClassLoader |
preferRestartClassLoader(java.lang.ClassLoader fallback)Returns a loader that sees the restarted application classes when DevTools restart is active. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
classLoader - the loader to inspect, possibly nulltrue when classLoader is Spring Boot DevTools'
RestartClassLoader itself
classLoader - the loader to inspect, possibly nulltrue when classLoader is the RestartClassLoader or
delegates to one through its parent chain, and so sees the restarted application classes Returns a loader that sees the restarted application classes when DevTools restart is
active. fallback is kept when it already does; otherwise the thread context class
loader is used when it does. When neither does, DevTools restart is not active on this
thread and fallback is returned, or this class's loader when fallback is
null.
fallback - the loader to use when DevTools restart is not active