Spring Boot-devtools hot deployment, basic configuration of server and tomcat

devtools hot deployment

Add devtools dependency to pom.xml file

<!-- 热部署 -->
<!-- 
	devtools可以实现页面热部署(即页面修改后会立即生效,这个可以直接在application.properties/application.yml文件中配置spring.thymeleaf.cache=false来实现)
	
	实现类文件热部署(类文件修改后不会立即生效),实现对属性文件的热部署。
	
	即devtools会监听classpath下的文件变动,并且会立即重启应用(发生在保存时机),
	注意:因为其采用的虚拟机机制,该项重启是很快的
	 (1)base classloader(Base类加载器):加载不改变Class,例如:第三方提供的jar包
	 (2)restart classloader(Restart类加载器):加载正在开发的Class
	 为什么重启很快,应为重启的时候只是加载了在开发的Class,没有重新加载第三方的jar包
 -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-devtools</artifactId>
	<!-- 
		optional=true,以来不会传递,该项目以来devtools;
		之后以来boot项目的项目如果想要使用devtools,需要重新引入
	 -->
	<optional>true</optional>
</dependency>

application.yml placement

spring:
  thymeleaf:
    #关闭缓存,及时刷新
    cache: true
  devtools:
    restart:
      #热部署生效
      enabled: true
      #设置重启目录,添加那个目录的文件需要restart
      additional-paths: src/main/java

 

Basic configuration of server and tomcat

server:
  # 配置端口号
  port: 8088
  servlet:
    # 配置context-path,一般来说这个配置在正式发布的时候不配置,配置了以后,访问的路径需要在端口后加上“/demo”
#    context-parameters: /demo   
    session:
      # session最大超时时间(分钟),默认30分钟
      timeout: 10        
   
  tomcat:
    # tomcat的URI编码
    uri-encoding: UTF-8

Configure the port number, you need to access the configured port when you visit, if you don’t configure it, the default is 8080

For the above sample code, you can view the articles in the Spring Boot development common technology blog directory .

Guess you like

Origin blog.csdn.net/qq_33369215/article/details/89931213