docs/Spring全家桶/SpringBoot/SpringBoot自带的热部署工具.md
SpringBootУÿдĶҪٵԣܱȽϷʱ䣻SpringBootŶԴṩspring-boot-devtoolsdevtoolsͼԵЧʡ@pdai
ȲȼӦеʱԶ£¼ػ滻classȣӦõһPSspring-boot-devtoolsṩķҲҪģֶֻʵԶضѡ
ϸϣҪȲȼ, JavaĿԣ
Ȳ
ȼ
LiveLoadṩͻԶظµĹߣΪLiveLoadLiveload֣ devtoolsѾLiveLoadǿwebӦãԶˢ£ ʱԿLiveLoad.
ͬһʱֻһLiveReload ʼӦó֮ǰȷûLiveReloadСIDEӦóֻеһӦó֧LiveReload
ͨʵԶʽȲ
spring-boot-devtools
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
spring-boot-devtools
<optional>true</optional> <!-- Էֹdevtoolsݵģ -->
</dependency>
</dependencies>
ʹIDEAߣַͨʽ
Ҳmvn compile봥£
1
File->Setting->Build,Execution,Deployment->Compile
ѡMake project automatically
2
ݼctrl+alt+shift+/
ѡRegistry
ѡcompiler.automake.allow.when.app.running
°汾IDEAFile->setting->Advanced Setttingsĵһã
spring:
devtools:
restart:
enabled: true #ÿȲ
additional-paths: src/main/java #Ŀ¼
exclude: WEB-INF/**
thymeleaf:
cache: false #ʹThymeleafģ棬رջ
spring-boot-devtoolsģǶʽLiveReloadԴʱڴˢ¡ LiveReloadչ֧ChromeFirefoxSafariԴlivereload.comء
ߴأfirefox:
װ֮ͨͼ
㲻ӦóʱLiveReloadԽspring.devtools.livereload.enabledΪfalse
ͬһʱֻһLiveReload ʼӦó֮ǰȷûLiveReloadСIDEӦóֻеһӦó֧LiveReload
ȻһЩʹdevtoolߣǺܹģ¼⣬һ⡣@pdai
ΪʲôͬӦãΪʲôֶǽʹspring-boot-devtoolsȲ
spring-boot-devtoolsʹClassLoaderһClassLoaderزᷢĵࣨjarһClassLoaderrestart ClassLoaderػĵࣨԶࣩ
̨һļ̣߳File Watcher****Ŀ¼еļ䶯ʱ ԭrestart ClassLoader¼µrestart ClassLoader
Ϊļ䶯jar¼أֻԶ࣬صȽ٣ȽϿ졣
ҲΪʲôͬӦãΪʲôֶʹspring-boot-devtoolsȲ
ԶмҪע:
¼ʲô־
ͨ¹ر
spring:
devtools:
restart:
log-condition-evaluation-delta: false
ijЩԴڸʱһҪĬ£ıԴ/META-INF/maven/META-INF/resources/resources/static/public/templatesȷᴥֳװҪԶЩųʹøspring.devtools.restart.excludeԡ磬Ҫų/static/public㽫ԣ
spring:
devtools:
restart:
exclude: "static/**,public/**"
ҪЩĬֵųøspring.devtools.restart.additional-excludeԡ
ͨʹʵֵġڴӦóַЧܺáǣʱᵼ⡣
Ĭ£IDE еκδĿʹáأκγ.jarļʹáء㴦һģĿҲÿģ鶼뵽 IDE УҪԶһЩΪˣԴһMETA-INF/spring-devtools.propertiesļ
spring-devtools.propertiesļrestart.excludeΪǰrestart.includeincludeԪӦñߵĿԼexcludeҪӦ롰BaseĿԵֵӦ·ʽģʽʾʾ
restart:
exclude:
companycommonlibs: "/mycorp-common-[\\w\\d-\\.]+\\.jar"
include:
projectcommon: "/mycorp-myproj-[\\w\\d-\\.]+\\.jar"
صϢ´ڴ鿴
devtoolԭ˵ӦֻڿԵʱʹãjarʱDzҪģSpringJAR
дӦóʱԱԶͨ java -jarʱᱻΪǡӦá
ãֻεлʹ SSL бʱӦ
£devtoolҲ߱Զ̵ԵԶ̿ͻӦóּڴ IDE СҪorg.springframework.boot.devtools.RemoteSpringApplicationʹӵԶĿͬ·СӦóΨһӵԶ URL
磬ʹ Eclipse Spring Toolsһmy-appѲ Cloud Foundry ΪĿִ²
еԶ̿ͻ˿б
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ ___ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | | _ \___ _ __ ___| |_ ___ \ \ \ \
\\/ ___)| |_)| | | | | || (_| []::::::[] / -_) ' \/ _ \ _/ -_) ) ) ) )
' |____| .__|_| |_|_| |_\__, | |_|_\___|_|_|_\___/\__\___|/ / / /
=========|_|==============|___/===================================/_/_/_/
:: Spring Boot Remote :: 2.5.4
2015-06-10 18:25:06.632 INFO 14938 --- [ main] o.s.b.devtools.RemoteSpringApplication : Starting RemoteSpringApplication on pwmbp with PID 14938 (/Users/pwebb/projects/spring-boot/code/spring-boot-project/spring-boot-devtools/target/classes started by pwebb in /Users/pwebb/projects/spring-boot/code)
2015-06-10 18:25:06.671 INFO 14938 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2a17b7b6: startup date [Wed Jun 10 18:25:06 PDT 2015]; root of context hierarchy
2015-06-10 18:25:07.043 WARN 14938 --- [ main] o.s.b.d.r.c.RemoteClientConfiguration : The connection to http://localhost:8080 is insecure. You should use a URL starting with 'https://'.
2015-06-10 18:25:07.074 INFO 14938 --- [ main] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2015-06-10 18:25:07.130 INFO 14938 --- [ main] o.s.b.devtools.RemoteSpringApplication : Started RemoteSpringApplication in 0.74 seconds (JVM running for 1.105)
Spring Boot ֵ֧һЩʹû磬ģ滺ѱģԱظģļ⣬Spring MVC ṩ̬ԴʱӦ HTTP ͷ
Ȼ**зdz棬ڿпܻʵ䷴**ʹոӦóĸġԭ spring-boot-devtools ĬϽûѡ
Thymeleaf ṩspring.thymeleaf.cacheģĻ棬ʹspring-boot-devtoolsģʱDzҪֶЩԵģΪspring-boot-devtoolsԶá
ôԶЩأDevToolsPropertyDefaultsPostProcessorҵӦĬá
public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostProcessor {
static {
Map<String, Object> properties = new HashMap<>();
properties.put("spring.thymeleaf.cache", "false");
properties.put("spring.freemarker.cache", "false");
properties.put("spring.groovy.template.cache", "false");
properties.put("spring.mustache.cache", "false");
properties.put("server.servlet.session.persistent", "true");
properties.put("spring.h2.console.enabled", "true");
properties.put("spring.web.resources.cache.period", "0");
properties.put("spring.web.resources.chain.cache", "false");
properties.put("spring.template.provider.cache", "false");
properties.put("spring.mvc.log-resolved-exception", "true");
properties.put("server.error.include-binding-errors", "ALWAYS");
properties.put("server.error.include-message", "ALWAYS");
properties.put("server.error.include-stacktrace", "ALWAYS");
properties.put("server.servlet.jsp.init-parameters.development", "true");
properties.put("spring.reactor.debug", "true");
PROPERTIES = Collections.unmodifiableMap(properties);
}
Ȼ㲻뱻ӦԱspring-boot-devtoolsĬã ͨspring.devtools.add-propertiesfalseapplication.ymlС
ͨspring-boot-devtools.ymlļӵ$HOME/.config/spring-bootĿ¼**ȫ devtools **
ӵЩļκԶʹ devtools Spring Boot Ӧó磬ҪΪʼʹôļҪӵspring-boot-devtoolsļУ
spring:
devtools:
restart:
trigger-file: ".reloadtrigger"
Ҳdevtoolʲôѡ
ʵʵĿУҲȥʹdevtool, Ϊ
https://github.com/realpdai/tech-pdai-spring-demos
https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.devtools
https://liayun.blog.csdn.net/article/details/116541775
Ȩ@pdai ԭӣhttps://pdai.tech/md/spring/springboot/springboot-x-hello-devtool.html