1.先搭建一个maven项目。
2.然后修改pom.xml如下图:
<?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.sxb</groupId>
<artifactId>singlespringboot</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/>
</parent>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
</dependencies>
</project>
3.然后编写一个测试类进行测试,如下:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by sxb-gt on 2017/12/28.
*/
@RestController
@EnableAutoConfiguration
public class Example {
@RequestMapping(value ="/home", method = RequestMethod.GET)
@ResponseBody
public String home(){
return "你好,Spring Boot";
}
public static void main(String[] args){
SpringApplication.run(Example.class, args);
}
}
注意:类的上面一定要加@EnableAutoConfiguration,否则启动会报错。
4.执行测试类中的main方法,控制台输出没有异常,则代表启动成功。
5.访问 http://localhost:8080/home/
版权声明:本文为lhxinbobo原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。