一、环境准备
1、JDK1.8
2、开发工具STS3.8.4
3、项目管理工具Maven3.5.0
二、新建MAVEN项目



三、编辑pom.xml文件
1、新增parent标签
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.3.RELEASE</version></parent>
2、新增jdk版本约束
<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>1.8</java.version></properties>
3、新增spring-boot-starter-web依赖
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency></dependencies>
4、完整pom.xml文件
<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>org.goldwind</groupId><artifactId>01HelloWorld</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging>-
<name>01HelloWorld</name><url>http://maven.apache.org</url>-
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.3.RELEASE</version></parent>-
<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>1.8</java.version></properties>-
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency></dependencies></project>
四、编写Controller
package org.goldwind;-
import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;-
@RestControllerpublic class HelloWorldController {@RequestMapping("/hello")public String hello(){return "Hello World!";}}
五、编写App.java
package org.goldwind;-
import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;-
/*** Hello world!**/@SpringBootApplicationpublic class App{public static void main( String[] args ){System.out.println( "Hello World!" );SpringApplication.run(App.class, args);}}
六、启动项目
以启动java工程的方式启动App.java中的main函数
访问路径:http://localhost:8080/hello
注意,如果MAVEN项目报错,请按如下方式解决:
Alt+F5——勾选当前项目(默认已经勾选)——OK