• spring boot 热部署


    参考: https://www.cnblogs.com/rcddup/p/7533125.html

    一、添加 devtools 依赖



            <!-- Spring boot 热部署 : 此热部署会遇到 java.lang.ClassCastException 异常 -->
            <!-- optional=true,依赖不会传递,该项目依赖devtools;之后依赖myboot项目的项目如果想要使用devtools,需要重新引入 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <optional>true</optional>
            </dependency>



      当配置了 devtools 后,我们在classpath修改任何文件项目都将会自动重启。

      (1)某些资源在更改时不一定需要触发重新启动。例如, Thymeleaf 模板可以就地进行编辑。默认情况下更改资源路径包括了:/META-INF/maven/META-INF/resources ,/resources ,/static ,/public 或者 /templates 不会触发重新启动, 但会触发实时重新加载。

    如果逆向排除这些路径,可以使用如下配置:

      spring.devtools.restart.exclude=static/**,public/**

      (2)如果要保留这些默认值并添加其他排除项, 请使用 spring.devtools.restart.additional-exclude 属性代替。

      (3)通过 System.setProperty("spring.devtools.restart.enabled", "false"); 方法,可以在SpringApplication.run()方法运行天使用关闭 devtools

      (4)当我们再次启动 App.java 的时候,使用的加载器就变为了 restartedMain 了,说明热部署已经成功。



       注意点:devtools 由于是双类加载机制,再结合了通用Mapper后可能会出现 java.lang.ClassCastException 异常(例如:说class x.x.A cannot be cast to x.x.A)

      解决方案就如下:

      在 src/main/resources 中创建 META-INF 目录,在此目录下添加 spring-devtools.properties 配置,内容如下:

      restart.include.mapper=/mapper-[\w-\.]+jar
      restart.include.pagehelper=/pagehelper-[\w-\.]+jar


  • 相关阅读:
    postgresql 2012 大会PPT下载 Joe
    Postgresql连接 Joe
    查看Postgresql的连接数 Joe
    greta使用
    CString GetFileDir(const CString& csFile)
    UnicodeToAnsi函数
    myeclipse优化方案
    bool CreatedMultipleDirectory( char* direct)
    LPWSTR GBK(LPCSTR plszUtf8, WCHAR* lpszGBK)
    真正整合资源的高手
  • 原文地址:https://www.cnblogs.com/pascal1000/p/10924125.html
Copyright © 2020-2023  润新知