Transferred from: http://www.cnblogs.com/chry/p/5876752.html
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"? ><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.chry </groupId> <artifactId>studySpringBoot</artifactId> <version>0.0.1-snapshot</version > <properties> <java.version>1.7</java.version> </properties> <!--inher It defaults from Spring Boot--<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> & lt;/parent> <!--Add Typical dependencies for a Web application--<dependencies> <depende Ncy> <groupid>org.springframework.boot</groupid> <artifactId>spring-boot-starter-web</artifactId> </dependency> &L T;/dependencies> <!--package as a executable jar--<build> <finalname>studyspringboo T</finalname> </build></project>
3. Then create a Java Class
1 package com.chry.study; 2 3 import org.springframework.boot.SpringApplication; 4 Import Org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 Import Org.springframework.stereotype.Controller; 6 Import org.springframework.web.bind.annotation.RequestMapping; 7 Import Org.springframework.web.bind.annotation.ResponseBody; 8 9 @Controller10 @EnableAutoConfiguration11 public class Samplecontroller { @RequestMapping ("/") @ResponseBody15 String Home () { "Hello world!"; }18 public static void Main (string[] args) throws Exception { Springapplication.run ( Samplecontroller.class, args); }22}
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