类 Restarter
- java.lang.Object
- org.springframework.boot.devtools.restart.Restarter
public class Restarter extends Object
Allows a running application to be restarted with an updated classpath. The restarter works by creating a new application ClassLoader that is split into two parts. The top part contains static URLs that don't change (for example 3rd party libraries and Spring Boot itself) and the bottom part contains URLs where classes and resources might be updated.The Restarter should be
initializedearly to ensure that classes are loaded multiple times. Mostly theRestartApplicationListenercan be relied upon to perform initialization, however, you may need to callinitialize(String[])directly if your SpringApplication arguments are not identical to your main method arguments.By default, applications running in an IDE (i.e. those not packaged as "fat jars") will automatically detect URLs that can change. It's also possible to manually configure URLs or class file updates for remote restart scenarios.
- 从以下版本开始:
- 1.3.0
- 另请参阅:
RestartApplicationListener,initialize(String[]),getInstance(),restart()
构造器概要
构造器 限定符 构造器 说明 protectedRestarter(Thread thread, String[] args, boolean forceReferenceCleanup, RestartInitializer initializer)Internal constructor to create a newRestarterinstance.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 voidaddClassLoaderFiles(ClassLoaderFiles classLoaderFiles)Add additionalClassLoaderFilesto be included in the next restart.voidaddUrls(Collection<URL> urls)Add additional URLs to be includes in the next restart.static voidclearInstance()Clear the instance.static voiddisable()Initialize and disable restart support.URL[]getInitialUrls()Return the initial set of URLs as configured by theRestartInitializer.static RestartergetInstance()Return the activeRestarterinstance.ObjectgetOrAddAttribute(String name, org.springframework.beans.factory.ObjectFactory<?> objectFactory)ThreadFactorygetThreadFactory()Return aThreadFactorythat can be used to create leak safe threads.protected voidinitialize(boolean restartOnInitialize)static voidinitialize(String[] args)Initialize restart support.static voidinitialize(String[] args, boolean forceReferenceCleanup)Initialize restart support.static voidinitialize(String[] args, boolean forceReferenceCleanup, RestartInitializer initializer)Initialize restart support.static voidinitialize(String[] args, boolean forceReferenceCleanup, RestartInitializer initializer, boolean restartOnInitialize)Initialize restart support for the current application.static voidinitialize(String[] args, RestartInitializer initializer)Initialize restart support.protected Throwablerelaunch(ClassLoader classLoader)Relaunch the application using the specified classloader.ObjectremoveAttribute(String name)voidrestart()Restart the running application.voidrestart(FailureHandler failureHandler)Restart the running application.protected voidstart(FailureHandler failureHandler)Start the application.protected voidstop()Stop the application.
构造器详细资料
Restarter
protected Restarter(Thread thread, String[] args, boolean forceReferenceCleanup, RestartInitializer initializer)
Internal constructor to create a newRestarterinstance.- 参数:
thread- the source threadargs- the application argumentsforceReferenceCleanup- if soft/weak reference cleanup should be forcedinitializer- the restart initializer- 另请参阅:
initialize(String[])
方法详细资料
initialize
protected void initialize(boolean restartOnInitialize)
addUrls
public void addUrls(Collection<URL> urls)
Add additional URLs to be includes in the next restart.- 参数:
urls- the urls to add
addClassLoaderFiles
public void addClassLoaderFiles(ClassLoaderFiles classLoaderFiles)
Add additionalClassLoaderFilesto be included in the next restart.- 参数:
classLoaderFiles- the files to add
getThreadFactory
public ThreadFactory getThreadFactory()
Return aThreadFactorythat can be used to create leak safe threads.- 返回:
- a leak safe thread factory
restart
public void restart()
Restart the running application.
restart
public void restart(FailureHandler failureHandler)
Restart the running application.- 参数:
failureHandler- a failure handler to deal with application that doesn't start
start
protected void start(FailureHandler failureHandler) throws Exception
Start the application.- 参数:
failureHandler- a failure handler for application that won't start- 抛出:
Exception- in case of errors
relaunch
protected Throwable relaunch(ClassLoader classLoader) throws Exception
Relaunch the application using the specified classloader.- 参数:
classLoader- the classloader to use- 返回:
- any exception that caused the launch to fail or
null - 抛出:
Exception- in case of errors
getOrAddAttribute
public Object getOrAddAttribute(String name, org.springframework.beans.factory.ObjectFactory<?> objectFactory)
removeAttribute
public Object removeAttribute(String name)
getInitialUrls
public URL[] getInitialUrls()
Return the initial set of URLs as configured by theRestartInitializer.- 返回:
- the initial URLs or
null
disable
public static void disable()
Initialize and disable restart support.
initialize
public static void initialize(String[] args)
Initialize restart support. Seeinitialize(String[], boolean, RestartInitializer)for details.- 参数:
args- main application arguments- 另请参阅:
initialize(String[], boolean, RestartInitializer)
initialize
public static void initialize(String[] args, RestartInitializer initializer)
Initialize restart support. Seeinitialize(String[], boolean, RestartInitializer)for details.- 参数:
args- main application argumentsinitializer- the restart initializer- 另请参阅:
initialize(String[], boolean, RestartInitializer)
initialize
public static void initialize(String[] args, boolean forceReferenceCleanup)
Initialize restart support. Seeinitialize(String[], boolean, RestartInitializer)for details.- 参数:
args- main application argumentsforceReferenceCleanup- if forcing of soft/weak reference should happen on- 另请参阅:
initialize(String[], boolean, RestartInitializer)
initialize
public static void initialize(String[] args, boolean forceReferenceCleanup, RestartInitializer initializer)
Initialize restart support. Seeinitialize(String[], boolean, RestartInitializer, boolean)for details.- 参数:
args- main application argumentsforceReferenceCleanup- if forcing of soft/weak reference should happen oninitializer- the restart initializer- 另请参阅:
initialize(String[], boolean, RestartInitializer)
initialize
public static void initialize(String[] args, boolean forceReferenceCleanup, RestartInitializer initializer, boolean restartOnInitialize)
Initialize restart support for the current application. Called automatically byRestartApplicationListenerbut can also be called directly if main application arguments are not the same as those passed to theSpringApplication.- 参数:
args- main application argumentsforceReferenceCleanup- if forcing of soft/weak reference should happen on each restart. This will slow down restarts and is intended primarily for testinginitializer- the restart initializerrestartOnInitialize- if the restarter should be restarted immediately when theRestartInitializerreturns nonnullresults
getInstance
public static Restarter getInstance()
Return the activeRestarterinstance. Cannot be called beforeinitialization.- 返回:
- the restarter
clearInstance
public static void clearInstance()
Clear the instance. Primarily provided for tests and not usually used in application code.