Spring boot学习笔记01

 

一、eclipse安装spring boot

Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。

方法一:Eclipse中的Help -> Eclipse Marketplace...搜索sts,或选择“Popular”标签,选择Spring Tool Suite (STS) for Eclipse插件,安装:

安装

Confirm

系统进行相关的安装:

安装完成后:

注:为了快速安装,关闭eclipse的所有更新:

方法二:install new software

第一步,查看eclipse的版本号

Help -> About eclipse IDE…

 

当前eclipse的版本号为4.10

第二步,检查安装路径

从官网https://spring.io/tools3/sts/all/查看升级地址:

将4.10的升级包下载地址提取到剪贴板:

https://download.springsource.com/release/TOOLS/update/3.9.7.RELEASE/e4.10/springsource-tool-suite-3.9.7.RELEASE-e4.10.0-updatesite.zip

第三步,安装Install new software

安装过程同上。一般全部安装。

安装后重新启动eclipse。

 

二、案例

浏览器发送hello请求,服务器响应请求并返回hello boot!

(一)新建项目 maven project(略)

(二)配置依赖pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"

  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-parent</artifactId>

        <version>2.1.3.RELEASE</version>

      <relativePath /> <!-- lookup parent from repository -->

  </parent>//新添加

  <groupId>com.microuse</groupId>

  <artifactId>kms01</artifactId>

  <version>0.0.1-SNAPSHOT</version>

    <packaging>war</packaging>

    <description>knowledge project for Spring Boot</description>

 

    <properties>

        <java.version>1.8</java.version>

    </properties>

 

    <dependencies>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web-services</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-webflux</artifactId>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-websocket</artifactId>

        </dependency>

 

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-tomcat</artifactId>

            <scope>provided</scope>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-test</artifactId>

            <scope>test</scope>

        </dependency>

        <dependency>

            <groupId>io.projectreactor</groupId>

            <artifactId>reactor-test</artifactId>

            <scope>test</scope>

        </dependency>

    </dependencies>

 

    <build>

        <plugins>

            <plugin>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-maven-plugin</artifactId>

            </plugin>

      </plugins>

  </build>

</project>

 

(三)编写spring boot主程序

import org.springframework.boot.SpringApplication;

/**

 * spring boot 主应用程序

 */

import org.springframework.boot.autoconfigure.SpringBootApplication;

 

@SpringBootApplication

public class SpringbootTest {

  public static void main(String[] args) {

      //启动spring boot应用

      SpringApplication.run(SpringbootTest.class, args);

  }

 

}

(四)编写业务逻辑

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

 

@Controller

public class TestContral {

   

  @ResponseBody

  @RequestMapping("/hello")//浏览器请求地址

  public String hello() {

      return "hello boot!";//返回给浏览器现实的内容

  }

 

}

(五)启动主应用程序:java application

注意,查看web服务器浏览地址:localhost:8080

在浏览器中查看

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值