使用eclipse创建一个简易的springboot项目
一:创建一个maven项目,这个就不多赘述了。
二:在pom文件里引入以下信息:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
三:在项目包根目录创建一个Application.class
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
四:在resources里面创建一个application.yml,编写格式注意,在缩进的时候用空格,不要用tab
server:
port: 8080
context-path: /springboot
五:创建一个与application.class同级别的package(controller),并创建SpringbootTestController.class
@RestController//@RestController注解相当于@ResponseBody + @Controller合在一起的作用。
public class SpringbootTestController {
@RequestMapping("/helloSpringboot")
String home() {
return "Hello World!";
}
}
在application.class直接run Java application,浏览器输入http://localhost:8080/springboot/helloSpringboot。