怎么在SpringBoot中实现热部署-创新互联

怎么在Spring Boot中实现热部署?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

十多年专注成都网站制作,成都定制网页设计,个人网站制作服务,为大家分享网站制作知识、方案,网站设计流程、步骤,成功服务上千家企业。为您提供网站建设,网站制作,网页设计及定制高端网站建设服务,专注于成都定制网页设计,高端网页制作,对成都玻璃贴膜等多个方面,拥有多年的网站营销经验。

1、引用devtools依赖



  org.springframework.boot

  spring-boot-devtools

  true

这样,当修改一个java类时就会热更新。

2、自定义配置热部署

以下配置用于自定义配置热部署,可以不设置。

# 热部署开关,false即不启用热部署

spring.devtools.restart.enabled: true

# 指定热部署的目录

#spring.devtools.restart.additional-paths: src/main/java

# 指定目录不更新

spring.devtools.restart.exclude: test/**

3、Intellij Idea修改

如果是idea,需要改以下两个地方:

1、勾上自动编译或者手动重新编译

File > Settings > Compiler-Build Project automatically

2、注册

ctrl + shift + alt + / > Registry > 勾选Compiler autoMake allow when app running

注意事项

1、生产环境devtools将被禁用,如java -jar方式或者自定义的类加载器等都会识别为生产环境。

2、打包应用默认不会包含devtools,除非你禁用SpringBoot Maven插件的excludeDevtools属性。

3、Thymeleaf无需配置spring.thymeleaf.cache: false,devtools默认会自动设置,点击参考完整属性。

下面是devtools自动配置的部分源码:

@Order(Ordered.LOWEST_PRECEDENCE)

public class DevToolsPropertyDefaultsPostProcessor implements EnvironmentPostProcessor {

  private static final Map PROPERTIES;

  static {

    Map properties = new HashMap();

    properties.put("spring.thymeleaf.cache", "false");

    properties.put("spring.freemarker.cache", "false");

    properties.put("spring.groovy.template.cache", "false");

    properties.put("spring.mustache.cache", "false");

    properties.put("server.session.persistent", "true");

    properties.put("spring.h3.console.enabled", "true");

    properties.put("spring.resources.cache-period", "0");

    properties.put("spring.resources.chain.cache", "false");

    properties.put("spring.template.provider.cache", "false");

    properties.put("spring.mvc.log-resolved-exception", "true");

    properties.put("server.jsp-servlet.init-parameters.development", "true");

    PROPERTIES = Collections.unmodifiableMap(properties);

  }

4、devtools会在windows资源管理器占用java进程,在开发工具里面杀不掉,只能手动kill掉,不然重启会选成端口重复绑定报错。

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联网站建设公司行业资讯频道,感谢您对创新互联建站的支持。

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、建站服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章题目:怎么在SpringBoot中实现热部署-创新互联
文章转载:http://pwwzsj.com/article/dgidps.html