The Hellocontroller of Springboot

Source: Internet
Author: User

1. Build the Environment

1.1 Create a new MAVEN project, the next step

1.2 Open the Pom file, first add <parent></parent> tags:

  <Parent>    <groupId>Org.springframework.boot</groupId>    <Artifactid>Spring-boot-starter-parent</Artifactid>    <version>1.5.0.RELEASE</version>  </Parent>

This dependency allows us to choose the most appropriate version number of the jar package we added, eliminating our choice of the version number.

1.3 Add the JDK version number to the <properties></properties> tab:

< java.version >1.7</java.version>

Default is 1.6

1.4 Add one more dependency

    < Dependency >        < groupId >org.springframework.boot</groupId>        <  Artifactid>spring-boot-starter-web</artifactid>    </dependency>    
  This dependency provides us with a dependency package such as MVC, AOP, and so on.

2. Create a startup class

  2.1 open App.java, add @springbootapplication annotations to this class, create a startup class 
2.2 Remove the code from the Main method, Replace with Springapplication.run (App.class, args), where the program starts.
 Package Cn.sto; Import org.springframework.boot.SpringApplication; Import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication  Public class App {    publicstaticvoid  main (string[] args)    {        Springapplication.run (App.class, args);}    }

3. Create Controller

 Package Cn.sto; Import org.springframework.web.bind.annotation.RequestMapping; Import Org.springframework.web.bind.annotation.RestController; @RestController  Public class Hellocontroller {    @RequestMapping ("/hello")    public  String Hello () {         return "Hello";    }}

4. Browser Testing

Browser input Http://127.0.0.1:8080/hello

Springboot comes with Tomcat, the default port number is 8080

  

The Hellocontroller of Springboot

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.