maven+eclipse创建第一个spring-boot项目
2017-09-04 本文已影响7816人
帅哥_刷哥
1.创建Maven项目

2.选择项目类型

3.选择项目

4.编写项目组和名称-finish即可

5.修改pom.xml文件
<!-- spring boot基本环境 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>

6.pom.xml中添加依赖
<!--web应用基本环境配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

7.pom.xml中添加编译插件
<build>
<plugins>
<!-- spring-boot-maven-plugin插件就是打包spring boot应用的 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

8.基础包和类

9.App.java
package com.shuai.spring_boot_1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}

10.OneController.java
package com.shuai.spring_boot_1.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class OneController {
@RequestMapping("/")
@ResponseBody
public String index(){
return "hello spring boot";
}
}

11.启动项目
运行 App.java 中的 main方法
12.访问项目
http://localhost:8080/
会访问到 OneController.java 中的index方法