我有一个使用Intellij IDE运行良好的Spring启动应用程序.即我启动了具有委托给SpringApplication.run的main方法的Application类.除了hotswap,一切都很好.当我更改源代码时,我被迫重新启动应用程序.即使我在调试模式下启动应用程序,我也看不到hotswap工作.我可以看到Intellij的Debug设置启用了hotswap.
我的观察表明,当我运行springboot应用程序时,使用的类路径是我的
/projects/MyProject/classes/production/....
classes/production更改代码时,下面的文件没有更新.Intellij IDE编译文件但不更新classes/production目录.如何使用IntelliJ IDE进行spring-boot热插拔?
我尝试了我在这里和文档中找到的所有提示和技巧,但仍然没有运气.我有Thymeleaf的Spring webapp.当我在IDEA中调用update时,不会重新加载资源和模板(它没有重新加载).然后,我可以在浏览器中按ctrl + f5疯狂,更改不存在.
一切都在一个Java类中配置,如下所示:
@EnableWebMvc
public class MvcConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware {
Run Code Online (Sandbox Code Playgroud)
我的文件夹结构现在看起来像 这样,但我也尝试将资源放在没有"静态"文件夹或webapp/resources的情况下.
ResourceHandlerRegistry:
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
super.addResourceHandlers(registry);
registry.addResourceHandler("/img/**").addResourceLocations("classpath:/static/img/");
registry.addResourceHandler("/css/**").addResourceLocations("classpath:/static/css/");
registry.addResourceHandler("/js/**").addResourceLocations("classpath:/static/js/");
}
Run Code Online (Sandbox Code Playgroud)
我在application.properties中指定了cache = false:
spring.thymeleaf.cache=false
Run Code Online (Sandbox Code Playgroud)
并在提到的MvcConfig类中:
@Bean
public SpringResourceTemplateResolver templateResolver() {
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setApplicationContext(this.applicationContext);
templateResolver.setPrefix("/WEB-INF/templates/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCacheable(false);
return templateResolver;
}
Run Code Online (Sandbox Code Playgroud)
根据SO的一些答案我添加了对devtools的依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>1.4.1.RELEASE</version>
<optional>true</optional>
</dependency>
Run Code Online (Sandbox Code Playgroud)
还是行不通.有人说用addResources = true添加maven启动插件,所以我做了:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.1.RELEASE</version>
<configuration>
<addResources>true</addResources>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我的想法设置正确,因为当我调用update时,我的Java类会立即重新加载.只有资源和html文件不是,我必须为它重新启动服务器.Actualy*.html文件并不是什么大不了的事,但是在每次小css和js更改之后重新启动服务器会让我失望很多,而且当我丢失了将近15个小时弄清楚什么是错误时,它开始真的很令人沮丧.
任何帮助将不胜感激.
我已经阅读了Spring Boot中的热插拔,但没有找到对我的情况有帮助的东西.
我在使用thymeleaf的嵌入式码头服务器上有一个spring-boot应用程序.我的应用程序将提供html,css,js(AngularJS)和REST服务.
文件夹结构是这样的:
/java
----
/resources
/static
/js
/css
/templates (html)
Run Code Online (Sandbox Code Playgroud)
的pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但是当我更改它们时,css/html/js并没有热部署.我每次都要重启服务器.+ bonus =当页面加载时它锁定资源(js)甚至Ant脚本也无法替换它们.
我可以在任何地方设置scanIntervalSeconds吗?
- 编辑 -
Main.java
@Configuration
@ComponentScan
@EnableJpaRepositories
@EnableAutoConfiguration
@Import({RepositoryRestMvcConfiguration.class, PersistenceConfig.class, ThymeleafConfig.class})
public class Main {
public static void main(String[] args) throws Exception {
SpringApplication.run(Main.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
我通过右键单击类和IDEA中的Debug来运行它.
spring-boot ×3
hotswap ×2
deployment ×1
java ×1
jetty ×1
maven ×1
spring ×1
spring-mvc ×1
thymeleaf ×1