binbinyouliiii
V2EX  ›  Java

SpringBoot 在 IDEA 上怎么自动更新静态资源

  •  
  •   binbinyouliiii · Jul 20, 2017 · 11323 views
    This topic created in 3397 days ago, the information mentioned may be changed or developed.

    之前没用过 springboot,今天试一试,发现更改静态文件后不会自动更新,必须得重启服务器才行。

    之前直接用 tomcat 和 jetty 的时候,用 war 包的形式,IDEA 的 Run/Debug Configuration 的窗口有 updata resouce 的选项,但是用 SpringBoot 就没有了,各位用 IDEA 开发的时候是怎么解决的。

    24 replies  •  2019-03-22 20:04:46 +08:00
    Miy4mori
    Miy4mori
    Jul 20, 2017 via iPhone
    1
    记得有个 livereload 之类的配置,写在配置文件里就行,前提是你没搞 webapps 这个幺蛾子目录。
    mosliu
    mosliu
    Jul 20, 2017
    2
    spring-boot-devtools
    yuankui
    yuankui
    Jul 20, 2017
    4
    官方有文档的
    mosliu
    mosliu
    Jul 20, 2017
    5
    使用 spring-boot-devtools
    然后只要 build, 自动重启
    tr0uble
    tr0uble
    Jul 20, 2017
    6
    Run -> Reload changed classes
    tr0uble
    tr0uble
    Jul 20, 2017
    7
    CTRL + F OR Build -> Build Project 也会提示你更新,debug 模式
    tr0uble
    tr0uble
    Jul 20, 2017
    8
    CTRL + F9
    zpf124
    zpf124
    Jul 20, 2017
    9
    zpf124
    zpf124
    Jul 20, 2017
    10
    眼瞎, 看错了
    bk201
    bk201
    Jul 20, 2017
    11
    打开自动编译,引入 spring-boot-devtools
    haozhang
    haozhang
    Jul 20, 2017 via iPhone
    12
    扔了,用 playframework
    tengj
    tengj
    Jul 20, 2017
    13
    spring.thymeleaf.cache=false;
    把静态缓存去掉啦,或者用 spring-boot-devtools 这个热部署插件
    具体可以看这篇热部署文章:
    http://tengj.top/2017/06/01/springboot10
    Spring Boot 干货系列:(十)开发常用的热部署方式汇总
    fudanglp
    fudanglp
    Jul 20, 2017
    14
    建议采用前后端分离姿势,前端采用 angular 或者 vue,用 webpack liveload,angular 可以参考 jhipster 生成的工程
    yzmm
    yzmm
    Jul 20, 2017
    15
    除了可以加 devtools,还可以直接用 idea 配置 tomcat 热部署
    springmarker
    springmarker
    Jul 21, 2017
    16
    @yuankui 这种方法早就试过了,没用
    @mosliu 设置了,没用
    @bk201 试过,没用
    @tengj 试过,没用
    @fudanglp 开发前端也得要 HTML 刷新啊,HTML 不刷新,就得重启服务器或者 CTRL+F9
    @yzmm springboot 并没有这个选项
    mosliu
    mosliu
    Jul 21, 2017
    17
    现在就在这么用,没问题
    引入 spring-boot-devtools 然后 build 就会更新
    要不你 idea 版本问题?
    Niphor
    Niphor
    Jul 21, 2017
    18
    也试了好多 只会用#6 楼的办法

    话说新版 idea 你们搜狗什么的输入法能用么?
    pythonee
    pythonee
    Jul 22, 2017
    19
    @haozhang 现在这个玩意,还会一 build 就拉一堆依赖吗
    haozhang
    haozhang
    Jul 22, 2017 via iPhone
    20
    @pythonee 哪个玩意运行不需要依赖呢....你可以下载离线包,不用第一次运行等很长时间的。
    bk201
    bk201
    Jul 24, 2017
    21
    @springmarker 信了你的邪,这么多人可以,你不行,不如把环境以及操作发上来看看
    yzmm
    yzmm
    Jul 27, 2017
    22
    @springmarker 修改 pom.xml:
    <packaging>war</packaging>
    然后再部署试试,如果还不行可以。利用 servler3.0 新特性动态加载,resources 目录下新建个 web.xml 然后配置:
    ```
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <listener>
    <listener-class>com.xxx.cloud.context.ContextLoaderListener</listener-class>
    </listener>
    </web-app>
    ```

    ContextLoaderListener.java
    ```
    package com.anbai.cloud.context;

    import com.anbai.cloud.config.CloudApplication;
    import org.springframework.boot.SpringApplication;

    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    import java.util.logging.Logger;

    /**
    * Cloud 启动监听器,利用 Servlet 3.x 动态创建 Spring 的 Servlet
    */
    public class ContextLoaderListener implements ServletContextListener {

    private static final Logger LOG = Logger.getLogger("info");

    @Override
    public void contextInitialized(ServletContextEvent sce) {
    System.setProperty("file.encoding", "UTF-8");
    SpringApplication.run(CloudApplication.class, null);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
    LOG.info("Context " + sce.getServletContext() + " Destroyed...");
    }

    }
    ```
    jack80342
    jack80342
    Oct 26, 2017❤️1
    23
    最近翻译了最新的 Spring boot 官方文档,欢迎反馈🙃,https://www.gitbook.com/book/jack80342/spring-boot/details
    shanlan
    shanlan
    Mar 22, 2019
    24
    @jack80342 请问是怎么翻译的?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1897 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 59ms · UTC 09:13 · PVG 17:13 · LAX 01:13 · JFK 04:13
    ♥ Do have faith in what you're doing.