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这个任务。

相关文章
相关标签/搜索