1、配置pom.xml文档

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5.  
  6. <groupId>com.easytest</groupId>
  7. <artifactId>rebushu</artifactId>
  8. <version>0.0.1-SNAPSHOT</version>
  9. <packaging>jar</packaging>
  10.  
  11. <name>rebushu</name>
  12. <url>http://maven.apache.org</url>
  13. <description>Demo project for Spring Boot</description>
  14.  
  15. <parent>
  16. <groupId>org.springframework.boot</groupId>
  17. <artifactId>spring-boot-starter-parent</artifactId>
  18. <version>1.5.9.RELEASE</version>
  19. <relativePath/> <!-- lookup parent from repository -->
  20. </parent>
  21.  
  22. <properties>
  23. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  24. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  25. <java.version>1.8</java.version>
  26. </properties>
  27.  
  28. <dependencies>
  29. <dependency>
  30. <groupId>org.springframework.boot</groupId>
  31. <artifactId>spring-boot-starter-web</artifactId>
  32. </dependency>
  33.  
  34. <dependency>
  35. <groupId>org.springframework.boot</groupId>
  36. <artifactId>spring-boot-starter-test</artifactId>
  37. <scope>test</scope>
  38. </dependency>
  39. <dependency>
  40. <groupId>com.alibaba</groupId>
  41. <artifactId>fastjson</artifactId>
  42. <version>1.2.15</version>
  43. </dependency>
  44.  
  45. <!-- spring boot devtools 依赖包. -->
  46. <dependency>
  47. <groupId>org.springframework.boot</groupId>
  48. <artifactId>spring-boot-devtools</artifactId>
  49. <optional>true</optional>
  50. <scope>true</scope>
  51. </dependency>
  52. </dependencies>
  53.  
  54. <!--构建节点-->
  55. <build>
  56. <plugins>
  57. <plugin>
  58. <groupId>org.springframework.boot</groupId>
  59. <artifactId>spring-boot-maven-plugin</artifactId>
  60. <configuration>
  61. <!--fork : 如果没有该项配置,肯呢个devtools不会起作用,即应用不会restart -->
  62. <fork>true</fork>
  63. </configuration>
  64.  
  65. </plugin>
  66.  
  67. </plugins>
  68. </build>
  69.  
  70. </project>

2、书写测试代码pojo(实体类)

  1. package com.easytest;
  2.  
  3. import com.alibaba.fastjson.annotation.JSONField;
  4.  
  5. import java.util.Date;
  6.  
  7. /**
  8. * Created by liuya on 2018-01-17.
  9. */
  10. public class UserPoJo
  11. {
  12. private int userId;
  13. private String userName;
  14. @JSONField(format="yyyy-MM-dd HH:mm:ss")
  15. private Date createTime;
  16.  
  17. public Date getCreateTime() {
  18. return createTime;
  19. }
  20.  
  21. public void setCreateTime(Date createTime) {
  22. this.createTime = createTime;
  23. }
  24.  
  25. public int getUserId() {
  26. return userId;
  27. }
  28.  
  29. public void setUserId(int userId) {
  30. this.userId = userId;
  31. }
  32.  
  33. public String getUserName() {
  34. return userName;
  35. }
  36.  
  37. public void setUserName(String userName) {
  38. this.userName = userName;
  39. }
  40.  
  41. @Override
  42. public String toString() {
  43. return "UserPoJo{" +
  44. "userId=" + userId +
  45. ", userName='" + userName + '\'' +
  46. ", createTime=" + createTime +
  47. '}';
  48. }
  49. }

3、书写测试服务器

  1. package com.easytest;
  2.  
  3. import com.alibaba.fastjson.serializer.SerializerFeature;
  4. import com.alibaba.fastjson.support.config.FastJsonConfig;
  5. import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
  6. import org.springframework.boot.SpringApplication;
  7. import org.springframework.boot.autoconfigure.SpringBootApplication;
  8. import org.springframework.http.MediaType;
  9. import org.springframework.http.converter.HttpMessageConverter;
  10. import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  11.  
  12. import java.util.ArrayList;
  13. import java.util.List;
  14.  
  15. @SpringBootApplication
  16. public class RebushuApplication extends WebMvcConfigurerAdapter {
  17.  
  18. /**
  19. // * 在这里我们使用 @Bean注入 fastJsonHttpMessageConvert
  20. // * @return
  21. // */
  22. @Override
  23. public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
  24.  
  25. // 1、需要先定义一个 convert 转换消息的对象;
  26. FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
  27.  
  28. //2、添加fastJson 的配置信息,比如:是否要格式化返回的json数据;
  29. FastJsonConfig fastJsonConfig = new FastJsonConfig();
  30. fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
  31.  
  32. //处理中文乱码
  33. List<MediaType> fastMediaTypes = new ArrayList<>();
  34. fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
  35. fastConverter.setSupportedMediaTypes(fastMediaTypes);
  36.  
  37. //3、在convert中添加配置信息.
  38. fastConverter.setFastJsonConfig(fastJsonConfig);
  39.  
  40. HttpMessageConverter<?> converter = fastConverter;
  41. converters.add(fastConverter);
  42. }
  43.  
  44. public static void main(String[] args) {
  45. SpringApplication.run(RebushuApplication.class, args);
  46. }
  47. }

4、书写controller代码

  1. package com.easytest;
  2.  
  3. import org.springframework.web.bind.annotation.RequestMapping;
  4. import org.springframework.web.bind.annotation.RestController;
  5.  
  6. import java.util.Date;
  7.  
  8. /**
  9. * Created by liuya on 2018-01-16.
  10. *
  11. * 测试用的一个helloworld例子
  12. */
  13.  
  14. @RestController
  15. public class ControllerJson {
  16.  
  17. @RequestMapping("user2")
  18. public UserPoJo hello(){
  19. //实体类赋值
  20. UserPoJo userPoJo = new UserPoJo();
  21. userPoJo.setUserId(111);
  22. userPoJo.setUserName("王小二");
  23. userPoJo.setCreateTime(new Date());
  24. //返回实体类
  25. return userPoJo;
  26. }
  27. }

5、编译器配置

(1)开启idea自动make功能

File--->setting--->如图:
           

(2)点击Compiler进入界面如图:(选择make project automatically)

(3)CTRL + SHIFT + A ----->查找Registry --->勾选compiler.automake.allow.when.app.running项目(详见:http://www.cnblogs.com/liuyangfirst/p/8317419.html)

6、maven启动,在编译器右侧栏点开右侧栏
      

7、访问网页测试一下是否联通

8、controller中加如下内容,然后F5刷新界面,如图就是成功实现热部署

  

IntelliJ IDEA 2017版 spring-boot-devtools实现热部署的更多相关文章

  1. IntelliJ IDEA Spring boot devtools 实现热部署

    一.spring-boot-devtools是一个为开发者服务的一个模块,其中最重要的功能就是自动部署新代码. 二.原理 使用了两个ClassLoader,一个ClassLoader用来加载那些不会变 ...

  2. Spring Boot入门系列(十五)Spring Boot 开发环境热部署

    在实际的项目开发过中,当我们修改了某个java类文件时,需要手动重新编译.然后重新启动程序的,整个过程比较麻烦,特别是项目启动慢的时候,更是影响开发效率.其实Spring Boot的项目碰到这种情况, ...

  3. Spring Boot 应用的热部署配置

    前言 所谓热部署,简单来说,就是代码修改后不需重启项目就可自动加载出新的内容. 注意:热部署在 debug 调试模式下才生效! IDEA 配置 在 IDE(IDEA)中开启相关项目自动构建选项 开启编 ...

  4. Spring Boot 2.0 热部署指南

    Spring Boot 2.0 支持热部署,实现方法很简单 Spring Boot 2.0 有几种热重载的选项. 推荐的方法是使用spring-boot-devtools 因为它提供了额外的开发时间功 ...

  5. Spring Boot 五种热部署方式

    [推荐]2019 Java 开发者跳槽指南.pdf(吐血整理)>>> 1.模板热部署 在SpringBoot中,模板引擎的页面默认是开启缓存的,如果修改了页面的内容,则刷新页面是得不 ...

  6. Spring Boot 五种热部署方式,极速开发就是生产力!

    1.模板热部署 在 Spring Boot 中,模板引擎的页面默认是开启缓存的,如果修改了页面的内容,则刷新页面是得不到修改后的页面的,因此我们可以在application.properties中关闭 ...

  7. IntelliJ IDEA 2017版 spring-boot2.0.4+mybatis 自动部署的细节问题

    一.加载pom依赖包 <!--spring-boot开发热部署--> <dependency> <groupId>org.springframework.boot& ...

  8. spring boot 中的热部署

    <plugin>    <groupId>org.springframework.boot</groupId>    <artifactId>sprin ...

  9. spring boot入门学习---热部署

    1.maven文件 2.application.properties文件配置

  10. Spring Boot学习笔记-配置devtools实现热部署

    写在前面 Spring为开发者提供了一个名为spring-boot-devtools的模块来使Spring Boot应用支持热部署,提高开发者的开发效率,无需手动重启Spring Boot应用. de ...

随机推荐

  1. unittest框架出报告乱码的问题解决

    跟着上面的步骤修改好后,unittest断言写法要写成下面这样才能展示非乱码

  2. java之Jsch实现Linux的文件上传与下载

    一.JSch是Java Secure Channel的缩写.JSch是一个SSH2的纯Java实现.它允许你连接到一个SSH服务器,并且可以使用端口转发,X11转发,文件传输等,当然你也可以集成它的功 ...

  3. solr查询优化(实践了一下效果比较明显)

    什么是filtercache? solr应用中为了提高查询速度有可以利用几种cache来优化查询速度,分别是fieldValueCache,queryResultCache,documentCache ...

  4. 使用Fiddler对Android手机的应用数据进行抓包分析

    文章源自: http://blog.csdn.net/zshq280017423/article/details/8928616/ 对于Android开发的同事最头疼的事情莫过于真机抓包,然后Fidd ...

  5. (翻译)React Container Components

    原文:Container Components Container Components 在 React 模式上对我的代码有最深远影响的一个模式叫 container component 模式. 在 ...

  6. 开关 toggleClass('hide')

    toggleClass 实现属性的反转 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  7. 我的Linux之路——windows10用WMware安装CentOS7.5 虚拟机详细步骤

    出自:https://www.jianshu.com/p/99f784d465f4 VMware简介:   VMware是一个虚拟PC的软件,可以在现有的操纵系统上虚拟出一个新的硬件环境,相当于模拟出 ...

  8. MVC4 AspNet MVC下的Ajax / 使用微软提供的Ajax请求脚本 [jquery.unobtrusive-ajax.min.js]

    源码参考:链接:http://pan.baidu.com/s/1pKhHHMj  密码:mkr4 1:新建-->项目-->Web-->ASP.NET MVC 4 Web 应用程序.命 ...

  9. 使用通配符配置action

    建立struts2wildcard项目,此实例基本仿照前面前面第7点的实例改写而成.为了使用通配符,只需要改写配置文件即可.此实例未使用通配时的配置文件如下: <action name=&quo ...

  10. 【319】Python 通过 Twilio 发短信

    参考:python利用twilio模块给自己发短信 参考:使用python实现往手机发短信(基于twilio) 步骤如下: 登录 Twilio 网站注册,貌似需要***,包括用户名.密码.手机号.项目 ...