2 minutes using Springboot to build a Spring MVC Web project under Eclipse

Source: Internet
Author: User

1. First create a MAVEN project with eclipse, and the normal MAVEN project can

2. Modify the POM as Follows:

<?XML version= "1.0" encoding= "UTF-8"?><Projectxmlns= "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.chry</groupId>    <Artifactid>Studyspringboot</Artifactid>    <version>0.0.1-snapshot</version>    <Properties>        <java.version>1.7</java.version>    </Properties>        <!--Inherit defaults from Spring Boot -    <Parent>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring-boot-starter-parent</Artifactid>        <version>1.4.0.RELEASE</version>    </Parent>    <!--Add Typical dependencies for a Web application -    <Dependencies>        <Dependency>            <groupId>Org.springframework.boot</groupId>            <Artifactid>Spring-boot-starter-web</Artifactid>        </Dependency>        </Dependencies>    <!--Package as an executable jar -    <Build>        <Finalname>Studyspringboot</Finalname>    </Build></Project>

3. Then create a Java Class

1  packagecom.chry.study;2 3 Importorg.springframework.boot.SpringApplication;4 Importorg.springframework.boot.autoconfigure.EnableAutoConfiguration;5 Importorg.springframework.stereotype.Controller;6 Importorg.springframework.web.bind.annotation.RequestMapping;7 Importorg.springframework.web.bind.annotation.ResponseBody;8 9 @ControllerTen @EnableAutoConfiguration one  public classSamplecontroller { a  -@RequestMapping ("/") - @ResponseBody the String Home () { -         return"Hello world!"; -     } -  +      public Static voidMain (string[] Args)throwsException { -Springapplication.run (samplecontroller.class, args); +     } a}

4. Component and run the class with the main method in Java application Mode

5. Browser Access http://localhost:8080/to display Hello World

=================================================

Simply explain the relevant

1. spring-boot-starter-parent:

The simplest way to springboot an officially recommended MAVEN management tool is to inherit it. The spring-boot-starter-parent contains the following information:

1), The default is compiled with java6, if you want to change to Java 1.7, then add the Java.version property in the Pom

2), using UTF-8 encoding

3), the implementation of a common testing framework (JUnit, hamcrest, mockito).

4), Intelligent Resource Filtering

5), Smart Plug-in configuration (exec plugin, surefire, Git commit ID, shade).

2. spring-boot-starter-web

Springboot Embedded web container, The lack of capital use Tomcat

3. @Controller

Note @controller in Java launches a spring MVC controller,

4. @EnableAutoConfiguration

@EnableAutoConfiguration is also required, it is used to turn on automatic configuration

5. @RequestMapping

In the example, the annotation maps "/" to the home () method that processes the Hello world output

6. @ResponseBody

In the example, this annotation takes the output string "Hello world" of home () directly as the response content of the HTTP request, not the view name commonly used in spring MVC

2 minutes using Springboot to build a Spring MVC Web project under Eclipse

Related Article

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.