Springboot devtools(熱部署)

關於devtools熱部署是一個提升工做效率的功能,從新部署文件只須要5秒。javascript

在修改,在保存,在配置頁面文件時,都會重啓。java

 

 

建立一個meven 項目web

向pom.xml中添加依賴包spring

<!-- spring boot devtools 依賴包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>

  

添加Spring-boot-maven-pluginjson

  <plugins>
    <build>     
   <!-- 這 是 Spring boot devtool plugin-->
                <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
                 <configuration>
                 <!-- fork: 若是沒有配置該項配置,devtools不會起做用的,即應用不會restear -->
                  <fork>ture</fork> 
                 </configuration> 
                </plugin>
        </plugins>
    </build>

  

建立一個class 文件app.javaapp

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;


import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;

/**使用@SpringBootAplication指定是spring boot的一個應用程序
 * Hello world!
 *
 */	
@SpringBootApplication
//extends WebMvcConfigurerAdapter
public class App 
{

	//在這裏咱們使用@Bean注入 fastJsonHttpMessageConvert
	@Bean
	public HttpMessageConverters fashJsonHttpMessageConverters(){
		FastJsonHttpMessageConverter fastConverter=new FastJsonHttpMessageConverter();
		
		FastJsonConfig fastJsonConfig = new FastJsonConfig();
		fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
		
		fastConverter.setFastJsonConfig(fastJsonConfig);
		HttpMessageConverter<?> converter =fastConverter;
		
		return new HttpMessageConverters(converter);
		
	}
	
    public static void main( String[] args )
    {
       SpringApplication.run(App.class, args);
    }
}

  以後建立一個controller.javamaven

import java.util.Date;spring-boot

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;ui

/**
* 使用的RestController 等價於@Controller和@RequestBody
* @author admin
*
*/
@RestControllerrest

public class HelloController {
/**
* @RequestMapping:映射到http://127.0.0.1:8080/hello
* @return
*/
@RequestMapping("/hello")
public String hello(){
return "hello";

}

}

  運行後你會發現輸出結果爲hello

以後更改return "hello" 爲return "hello11111"

等待五秒以後,頁面刷新輸出結果爲hello11111

相關文章
相關標籤/搜索