【问题标题】:Spring Boot + Jetty & hot deploymentSpring Boot + Jetty & 热部署
【发布时间】:2014-06-17 07:56:05
【问题描述】:

我已经阅读了Hot swapping in Spring Boot,但没有找到对我的案子有帮助的东西。

我在使用 thymeleaf 的嵌入式码头服务器上有一个 spring-boot 应用程序。我的应用程序将提供 html、css、js(AngularJS) 和 REST 服务。

文件夹结构是这样的:

/java
   ----
/resources
   /static
       /js
       /css
   /templates (html)

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>

但是当我更改 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);
   }
}

我已经通过在 IDEA 中右键单击类和调试来运行它。

【问题讨论】:

    标签: spring maven deployment jetty spring-boot


    【解决方案1】:

    你是如何启动应用程序的?如果您使用带调试模式的 IDE,它应该可以工作(除了我认为是 Windows 操作系统的锁定问题),或者如果您使用“mvn spring-boot:run”或“gradle bootRun”启动它。

    【讨论】:

    • 谢谢 :-) "mvn spring-boot:run" 正在工作,如何从终端以调试模式运行它?
    • MAVEN_OPTS= -agentlib:jdwp=transport=dt_socket,server=y,address=8000 怎么样?
    • 我已经把它放在 Maven->Importing->VM options for importer 但没有运气。我仍然应该使用“mvn spring-boot:run”运行它吗?将服务器更改为 localhost?
    • 对不起,我没有遵循。什么是“进口商”?如果您在命令行上运行,只需设置一个环境变量(如建议的那样,使用server=y)。如果您想了解有关如何执行此操作的更多信息,请谷歌“java 远程调试”。
    • 在嵌入式 Tomcat 和 FreeMarker 中遇到了同样的问题,Dave 的解决方案奏效了:mvn spring-boot:run
    【解决方案2】:

    我使用 NetBeans 8.0.1 进行开发。 我修复了 src/main/resources 中未重新加载静态资源的问题,例如 css(在 src/main/resources/resources/css 中(是的,真的是两次“资源”!),html-thymeleaf-templates(在 src/main/资源/模板)通过以下方式:

    • 我的 Spring Boot webapp 是一个 JAR 项目 (pom.xml)
    • 添加 src/main/resources/application.properties:
      • spring.template.cache=false
      • spring.thymeleaf.cache=false
    • 添加了自定义 maven 构建:项目 - 属性 - 自定义... - 目标...
    • 执行目标:spring-boot:run
    • 设置属性:
      • jpda.listen=maven(以调试模式运行)
      • Env.spring.profiles.active=DEV(可选,但我需要它用于不同的 SpringConfig-...。开发、生产中的属性...)

    只需运行自定义 maven 构建,即可在调试模式下启动 webapp。 Thymeleaf 模板(位于 src/main/resources/templates 中,例如 index.html(不是 .xhtml!))的更改在浏览器重新加载时立即可见。

    【讨论】:

      【解决方案3】:

      如果你将 css 和 java 脚本移动到一个文件夹下 src/main/java/webapp 它应该可以工作。

      由于某些原因,src/main/java/resources 下的资源在更改时似乎没有热部署。

      为了解决这个问题,我添加了上面的帖子建议

      • spring.template.cache=false

      • spring.thymeleaf.cache=false 到资源文件夹中的 Application.properties。

      注意: 我也加了这个

      • -javaagent:springloaded-1.2.0.RELEASE.jar -noverify

      作为 vm 运行时参数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-04
        • 2012-05-06
        • 2012-09-26
        • 1970-01-01
        相关资源
        最近更新 更多