zoukankan      html  css  js  c++  java
  • Eclipse引入SpringBoot

    从这一博客开始学习SpringBoot,今天学习Eclipse配置SpringBoot.Eclipse导入SpringBoot有两种方式,一种是在线一个是离线方式。

    一、在线安装

    点击Eclipse中的help->Eclipse Marketplace,搜索sts,如下图,可一直报错下面的错误,所以又下载离线包进行的安装。

    二、离线安装

    开始的时候我下载的是springsource-tool-suite-3.9.4.RELEASE-e4.7.3a-updatesite这个版本。然后help->Install New Software->Add->Archive,这里由于我没解压所以选的是Archive,选择要安装的组件,点击Next.

    三、使用SpringBoot创建项目

    上面配置好之后可以使用SpringBoot来尝试着新建一个web项目。配置之后再New Project的页面会显示出Spring Boot选项,选择 Spring Starter Project。

    配置项目名称,版本等信息。

    这里选择创建web项目

    创建完成之后项目的目录结构如下图

    四、测试

    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.

    五、出现的错误

    如果启动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这个任务。

  • 相关阅读:
    造轮子 | 怎样设计一个面向协议的 iOS 网络请求库
    win7 激活码 秘钥
    python-pptx
    pycharm
    itop 环境
    Ubuntu上安装MongoDB(译)
    python之fabric(二):执行模式(转)
    python之fabric(一):环境env
    Windows下pip安装包报错:Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat
    vagrant系列教程(四):vagrant搭建redis与redis的监控程序redis-stat(转)
  • 原文地址:https://www.cnblogs.com/5ishare/p/8994613.html
Copyright © 2011-2022 走看看