配置环境:eclipse/springboot-2.3.4.RELEASE
添加所需要的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
添加配置项
网上有小伙伴说要加上配置项:
spring.devtools.restart.additional-paths:src/main/resources
实际上在这个地方有个问题,不加这个好像也可以正常使用,所以就去看了下devtools的源码:
public String[] getAllExclude() {
List<String> allExclude = new ArrayList<>();
if (StringUtils.hasText(this.exclude)) {
allExclude.addAll(StringUtils.commaDelimitedListToSet(this.exclude));
}
if (StringUtils.hasText(this.additionalExclude)) {
allExclude.addAll(StringUtils.commaDelimitedListToSet(this.additionalExclude));
}
return StringUtils.toStringArray(allExclude);
}
实际上devtools有一个默认的识别路径,还有一个可以支持配置的路径,就是在配置文件中加入的内容。
所以对于有没有必要加这个配置,就要去看看这么默认项中是否包含我们设置的内容:
private static final String DEFAULT_RESTART_EXCLUDES = "META-INF/maven/**,"
+ "META-INF/resources/**,resources/**,static/**,public/**,templates/**,"
+ "**/*Test.class,**/*Tests.class,git.properties,META-INF/build-info.properties";
/**
* Whether to enable automatic restart.
*/
private boolean enabled = true;
/**
* Patterns that should be excluded from triggering a full restart.
*/
private String exclude = DEFAULT_RESTART_EXCLUDES;
其实到这里基本就够了,一切都正常了,但是还想问一句DEFAULT_RESTART_EXCLUDES定义的字符串是什么意思?怎么理解?所说实话我没有看明白这个具体怎么和eclipse中的代码结构对应起来,哪个代表src/main/java/xx?...手动@大佬
测试效果
改一下端口号,然后保存