
正文
IDEA下搭建简单的SpringBoot工程应用
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
(1)File->new,选择maven,创建一个空项目,直接next.
(2)填写工程名,next.
(3)填写项目名,next,创建一个基于maven的空Java项目.
(4)在pom文件中引入SpringBoot相关依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
(5)新建一个controller 包,用于存放所有的controller,使用SampleController为第一个测试用例。代码如下:
/**
* Created by Song on 2017/2/15.
* 官方示例工程中的测试代码
*/
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
} public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
(6)直接点击运行该main函数,再浏览器链接栏,输入地址http://localhost:8080/,就可以看到打印的字符串”Hello World!”了。






