你的eclipse須要先安裝java
首先新建Maven工程web
勾選第一個按鈕,第三個是選擇working set ,你能夠不選spring
下一步,配置工程信息,注意打包爲jarapp
打開pom.xml文件,添加spring-boot依賴eclipse
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
新建文件src/main/hello/HelloController.javamaven
package hello; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @RequestMapping("/") public String hello(){ return "Greetings from Spring Boot!"; } }
新建src/main/hello/Application.javaspring-boot
package hello; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { public static void main(String[] args) { // http://localhost:8080/ SpringApplication.run(Application.class, args); } }
運行Applicationui
出現一堆:spa
訪問localhost:8080/code
File-》new-》other
選擇starter項目
下一步
下一步
勾選Web,Finish。能夠看到項目結構與咱們本身建的Maven有些不同。
新建一個Controller
package com.example.demo; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @RequestMapping("/") public String hello(){ return "Welcome to start SpringBoot!"; } }
運行
運行結果
比起原來的Spring項目,構建過程簡單多了