Eclipse引入SpringBoot

從這一博客開始學習SpringBoot,今天學習Eclipse配置SpringBoot.Eclipse導入SpringBoot有兩種方式,一種是在線一個是離線方式。java

1、在線安裝web

點擊Eclipse中的help->Eclipse Marketplace,搜索sts,以下圖,可一直報錯下面的錯誤,因此又下載離線包進行的安裝。spring

2、離線安裝瀏覽器

開始的時候我下載的是springsource-tool-suite-3.9.4.RELEASE-e4.7.3a-updatesite這個版本。而後help->Install New Software->Add->Archive,這裏因爲我沒解壓因此選的是Archive,選擇要安裝的組件,點擊Next.springboot

3、使用SpringBoot建立項目app

上面配置好以後能夠使用SpringBoot來嘗試着新建一個web項目。配置以後再New Project的頁面會顯示出Spring Boot選項,選擇 Spring Starter Project。ide

配置項目名稱,版本等信息。學習

這裏選擇建立web項目測試

建立完成以後項目的目錄結構以下圖ui

4、測試

package com.example.demo; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @RestController //@Controller //@ResponseBody
@RequestMapping("/sbs") public class helloController { @RequestMapping("/hello") public String Hello(){ return "Hello World"; } }
View Code

這裏須要注意上圖的紅色框的部分,這裏使用的是@RestController,其實也能夠使用下面註釋的兩個註解。點擊CuiywTestApplication.java右鍵Run As->Spring Boot App啓動。下圖是啓動成功的日誌。

在瀏覽器輸入http://localhost:8080/sbs/hello,能夠看到下圖返回的hello world.

5、出現的錯誤

若是啓動springboot以後再次啓動時就會報錯,APPLICATION FAILED TO START, Failed to start connector [Connector[HTTP/1.1-8080]]

***************************
APPLICATION FAILED TO START
***************************

Description:

The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured.

Action:

Verify the connector's configuration, identify and stop any process that's listening on port 8080, or configure this application to listen on another port.
View Code

這裏我直接經過任務管理器->用戶,結束javaw:Java(TM) Platform SE binary這個任務。

相關文章
相關標籤/搜索