美文网首页Spring Boot&Spring CloudSpring BOOTIT技术篇
Spring Boot 静态资源无法热加载的解决方法

Spring Boot 静态资源无法热加载的解决方法

作者: 简单的土豆 | 来源:发表于2017-05-18 17:03 被阅读514次

spring-boot-maven-plugin中添加addResources配置项:

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <addResources>true</addResources>
                </configuration>
            </plugin>

使用mvn spring-boot:run启动项目,而不是使用main()方法,这样修改静态资源后便即时生效(和spring-boot-devtools没半毛钱关系),下面是官方解释。

When addResources is enabled, any src/main/resources folder will be added to the application classpath when you run the application and any duplicate found in target/classes will be removed. This allows hot refreshing of resources which can be very useful when developing web applications. For example, you can work on HTML, CSS or JavaScript files and see your changes immediately without recompiling your application. It is also a helpful way of allowing your front end developers to work without needing to download and install a Java IDE.

参考:Spring Boot Reference Guide 82. Hot swapping

相关文章

网友评论

  • 流河:谢啦,真的可以,maven 启动那个地方写的有些不清楚,命令行应该是 mvn spring-boot:run
    简单的土豆:好的,我把冒号去掉,细节~

本文标题:Spring Boot 静态资源无法热加载的解决方法

本文链接:https://www.haomeiwen.com/subject/xawsxxtx.html