我正在使用spring-boot v1.3.5.RELEASE开发一个应用程序,该应用程序不使用@SpringBootApplication
或@EnableAutconfiguration
(客户要求)。
我想使spring-boot-devtools
在我的IDE中具有“重新启动”功能。我把它作为依赖项,点击mvn spring-boot:run
。重新启动器有效:
DEBUG o.s.b.d.r.Restarter - Creating new Restarter for thread Thread[main,5,main]
DEBUG o.s.b.d.r.Restarter - Immediately restarting application
DEBUG o.s.b.d.r.Restarter - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@22843e39
DEBUG o.s.b.d.r.Restarter - Starting application application.Application with URLs [file:/D:/git/repos/...]
但是在IDE代码修改和修改后(在Eclipse中为Ctrl + B),它不会重新加载。
问题似乎是devtools依赖于@EnableAutconfiguration
(装有META-INF/spring.factories
的工厂)进行配置(我不能使用此注释)。
基本上,我需要一个人做(参见下面的devtools spring.factories
文件的内容):
# Application Initializers
org.springframework.context.ApplicationContextInitializer=\
org.springframework.boot.devtools.restart.RestartScopeInitializer
# Application Listeners
org.springframework.context.ApplicationListener=\
org.springframework.boot.devtools.restart.RestartApplicationListener
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration,\
org.springframework.boot.devtools.autoconfigure.LocalDevToolsAutoConfiguration,\
org.springframework.boot.devtools.autoconfigure.RemoteDevToolsAutoConfiguration
# Environment Post Processors
org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.boot.devtools.env.DevToolsHomePropertiesPostProcessor,\
org.springframework.boot.devtools.env.DevToolsPropertyDefaultsPostProcessor
# Restart Listeners
org.springframework.boot.devtools.restart.RestartListener=\
org.springframework.boot.devtools.log4j2.Log4J2RestartListener
我该怎么做(我不太会流利的Spring-boot语言)?
答案 0 :(得分:1)
您应该能够通过自己的@Import
类@Configuration
来使用要使用的DevTools自动配置类。您可能不需要远程支持,在这种情况下,满足以下条件即可:
@Configuration
@Import({LocalDevToolsAutoConfiguration.class, DevToolsDataSourceAutoConfiguration.class})
class ManaulDevToolsConfiguration {
}
在极少数情况下,您想使用自己的Bean来代替任何DevTools的自动配置的Bean,您需要仔细订购,以确保在DevTools的自动配置之前定义了您的Bean导入类,并对缺少的bean条件进行评估。