標籤:string bin lin ppi 依賴 web cal bind 檔案
你的eclipse需要先安裝
Spring Tool Suite?
首先建立Maven工程
勾選第一個按鈕,第三個是選擇working set ,你可以不選
下一步,配置工程資訊,注意打包為jar
開啟pom.xml檔案,添加spring-boot依賴
<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.java
package hello;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class HelloController { @RequestMapping("/") public String hello(){ return "Greetings from Spring Boot!"; }}
建立src/main/hello/Application.java
package hello;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class Application { public static void main(String[] args) { // http://localhost:8080/ SpringApplication.run(Application.class, args); }}
運行Application
出現一堆:
訪問localhost:8080/
Eclipse搭建SpringBoot之HelloWorld