SpringBoot入门教程(超详细)

这里写目录标题
Spring Boot 简介
微服务
环境准备
maven设置
IDEA设置
使用SpringBoot创建一个HellWorld应用
1、创建一个maven工程(spring-boot-01-helloworld)
2、在pom.xml中导入spring boot相关的依赖
3、编写一个主程序
4、编写相关的Controller
5、运行主程序
简化部署
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标签添加以下配置:

jdk‐1.8 true 1.8

1、创建一个maven工程(spring-boot-01-helloworld)
项目目录:
在这里插入图片描述
2、在pom.xml中导入spring boot相关的依赖

spring-boot-dependencies
org.springframework.boot
1.5.10.RELEASE

org.springframework.boot spring-boot-starter-web 1 2 3 4 5 6 7 8 9 10 11 12 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文件中假如以下代码:

org.springframework.boot spring-boot-maven-plugin repackage 2、然后,我们将应用打包 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210225153338594.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM4MTI3NDg3,size_16,color_FFFFFF,t_70) 3、然后再target文件夹下就可以看到spring-boot-01-helloworld-1.0-SNAPSHOT.jar ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210225153356986.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM4MTI3NDg3,size_16,color_FFFFFF,t_70) 4、复制到桌面(随便哪,个人选择),打开cmd窗口,切换到jar包所在位置,我的是桌面,然后输入:java -jar spring-boot-01-helloworld-1.0-SNAPSHOT.jar,运行效果如下。 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210225153432739.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzM4MTI3NDg3,size_16,color_FFFFFF,t_70)

5、打开浏览器访问:http://localhost:8080/hello,同样可以看到HelloWord

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值