转载来自CSDN:https://blog.csdn.net/weixin_43883917/article/details/113943149

Spring Boot 简介

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

  • 简化Spring应用开发的一个框架
  • 整个Spring技术栈的一个大整合
  • J2EE开发的一站式解决方案

微服务

微服务:每一个功能元素最终都是一个可独立替换和独立升级的软件单元。

详情参考:微服务文档

环境准备

  • jdk1.8:Spring Boot 推荐jdk1.7及以上
  • maven3.x:maven 3.3以上版本
  • IntelliJIDEA:或者STS
  • SpringBoot 1.5.9.RELEASE:1.5.10

maven设置

在maven 的settings.xml配置文件的profiles标签添加以下配置:

<profile>
	<id>jdk‐1.8</id>
	<activation>
		<activeByDefault>true</activeByDefault>
		<jdk>1.8</jdk>
	</activation>
	<properties>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
	</properties>
</profile>

IDEA设置

把maven整合到idea。
在这里插入图片描述

使用SpringBoot创建一个HellWorld应用

功能:浏览器发送hello请求,服务器接受请求并处理,响应Hello World字符串。

1、创建一个maven工程(spring-boot-01-helloworld)

项目目录:
在这里插入图片描述

2、在pom.xml中导入spring boot相关的依赖

<parent>
  <artifactId>spring-boot-dependencies</artifactId>
     <groupId>org.springframework.boot</groupId>
     <version>1.5.10.RELEASE</version>
 </parent>

 <dependencies>
     <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-web</artifactId>
     </dependency>
 </dependencies>

3、编写一个主程序

HelloWorldMainApplication:

package com.keafmd;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Keafmd
 *
 * @ClassName: HelloWorldMainApplication
 * @Description: 主程序
 * @author: 牛哄哄的柯南
 * @date: 2021-02-22 15:00
 */
@SpringBootApplication
public class HelloWorldMainApplication {
    public static void main(String[] args) {

        //Spring应用启动起来
        SpringApplication.run(HelloWorldMainApplication.class,args);
    }
}

4、编写相关的Controller

HelloController:

package com.keafmd.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Keafmd
 *
 * @ClassName: HelloController
 * @Description:
 * @author: 牛哄哄的柯南
 * @date: 2021-02-22 15:04
 */
@Controller
public class HelloController {

    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){
        return "Hello World!";
    }
}

5、运行主程序

在这里插入图片描述
运行结果:
在这里插入图片描述
打开浏览器访问:http://localhost:8080/hello
在这里插入图片描述

OK,至此,第一个SpringBoot的HelloWorld就大功告成了。【amazing~】

简化部署

1、我们在pom.xml文件中假如以下代码:

<!-- 这个插件,可以将应用打包成一个可执行的jar包  -->
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

2、然后,我们将应用打包
在这里插入图片描述
3、然后再target文件夹下就可以看到spring-boot-01-helloworld-1.0-SNAPSHOT.jar
在这里插入图片描述
4、复制到桌面(随便哪,个人选择),打开cmd窗口,切换到jar包所在位置,我的是桌面,然后输入:java -jar spring-boot-01-helloworld-1.0-SNAPSHOT.jar,运行效果如下。在这里插入图片描述
5、打开浏览器访问:http://localhost:8080/hello,同样可以看到HelloWord
在这里插入图片描述

这样的部署就变得十分简单了。

以上就是SpringBoot入门教程(超详细)的全部内容。

看完如果对你有帮助,感谢点赞支持!
如果你是电脑端的话,看到右下角的 “一键三连” 了吗,没错点它[哈哈]

在这里插入图片描述

加油!

共同努力!

Keafmd