温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

SpringBoot中怎样实现热部署

发布时间:2021-08-09 17:05:16 来源:亿速云 阅读:172 作者:Leah 栏目:编程语言

这期内容当中小编将会给大家带来有关SpringBoot中怎样实现热部署,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

1、引用devtools依赖

<dependency>  <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-devtools</artifactId>  <optional>true</optional></dependency>

这样,当修改一个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<String, Object> PROPERTIES;  static {    Map<String, Object> properties = new HashMap<String, Object>();    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掉,不然重启会选成端口重复绑定报错。

上述就是小编为大家分享的SpringBoot中怎样实现热部署了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI