Spring-boot-devtools

Source: Internet
Author: User

Create a new Maven Project and we have both class under the package Com.example.demo like below screen shot.

This page mainly focus on how to make the change you make ready to show the result without restarting Spring boot app Lication with Maven.

 package   Com.example.demo;  import   org.springframework.boot.SpringApplication;  import   org.springframework.boot.autoconfigure.springbootapplication;@ Springbootapplication  public  class   demoapplication { public  static  void   main ( String[] args) {Springapplication.run (demoapplication. ) class     
 package   Com.example.demo;  import   org.springframework.web.bind.annotation.RequestMapping;  import   Org.springframework.web.bind.annotation.RequestMethod;  import   Org.springframework.web.bind.annotation.RestController; @RestController  Span style= "COLOR: #0000ff" >public  class   Hellocontroller {@RequestMapping (value  = "Hi", Method = Requestmethod.get) public   String Sayhi () { return " Hello world! "    ; }}
<?xml version= "1.0" encoding= "UTF-8"? ><project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http ://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > <modelversion>4.0.0 </modelVersion> <groupId>com.example</groupId> <artifactId>demo</artifactId> <ve Rsion>0.0.1-snapshot</version> <packaging>jar</packaging> <name>demo</name> < Description>demo Project for Spring boot</description> <parent> <groupId>org.springframework.boot</groupId> &        Lt;artifactid>spring-boot-starter-parent</artifactid> <version>1.5.6.RELEASE</version> <relativePath/> </parent> <properties> <project.build.sourceencoding>utf-8</projec T.build.sourceencoding> <project.reporting.outputencoding>utf-8</project.reporting.outputencoding > <java.version>1.8</java.version> </properties> <dependencies> <depende Ncy> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starte r-web</artifactid> </dependency> <dependency> <groupid>org.springframewor K.boot</groupid> <artifactId>spring-boot-starter-test</artifactId> <scope>te St</scope> </dependency> </dependencies> <build> <plugins> <plugin> &L T;groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifa ctid> </plugin> </plugins> </build></project>

Then,run the DemoApplication as Java application or Spring Boot App (if you is using STS), after the application starts up , input the link localhost:8080/hi, you'll get the Hello world! As the output.

If you are want to change the requestmapping from "hi" to "hello", it is ready for use, it is need to change it and res Tart the application.

With spring-boot-devtools We just change the code and save it without restart the application manually,spring Boot Help us restart the application .

To achieve this, any need to do is adding the spring-boot-devtools dependency in the Pom.xml and make sure Proj Ect>build automatically is chosen in the IDE

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

On the condition so you add the dependency in the Pom.xml file and you don ' t choose the build automatically within the I DE (Eclipse or STS here), then when you change the the the requestmapping from "hi" to "Hello" and save it,spring boot would not Restart the application for you has to bulid the pom file and restart the application manualy. Because the Spring-boot-devtools monitor the code under the target to restart the application to make the change for you made Ready-to-use, so-choose the build atuomatically and change requestmapping and save it, the IDE build and the code Unde R the target is updated to trigger the restart of the spring boot application automatically.

For more details,please Refer the spring boot devtools reference guide:http://docs.spring.io/spring-boot/docs/current/r Eference/html/using-boot-devtools.html




Spring-boot-devtools

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.