Spring Boot的简单介绍及构建-刘宇

作者:刘宇
CSDN博客地址:https://blog.csdn.net/liuyu973971883
有部分资料参考,如有侵权,请联系删除。如有不正确的地方,烦请指正,谢谢。

一、Spring Boot介绍

  • Spring Boot 是由 Pivotal 团队提供用来简化 Spring 的搭建和开发过程的全新框架。随着近些年来微服务技术的流行,Spring Boot 也成了时下炙手可热的热点技术。
  • Spring Boot 去除了大量的 xml 配置文件,简化了复杂的依赖管理,配合各种 starter 使用,基本上可以做到自动化配置。Spring 可以做的事情,现在用 Spring boot 都可以做。

二、创建Spring Boot应用

2.1、方式一

登录https://start.spring.io网站进行创建

在这里插入图片描述

点击生成后会自动下载代码,随后加这个项目添加到开发工具中即可。

2.2、方式二

使用idea开发工具创建,当然其他开发工具也可创建

  • 第一步:new project,选择spring生成工具,并选择对应的java版本和spring starter的地址
    在这里插入图片描述

  • 第二步:添加项目相关信息
    在这里插入图片描述

  • 第三步:选择spring boot的依赖库
    在这里插入图片描述

  • 第四步:添加项目名称和存放目录
    在这里插入图片描述

  • 第五步:运行spring boot项目

找到springboot的启动类,然后运行那么我们这个springboot的web应用就运行起来了,默认地址:http://localhost:8080/

在这里插入图片描述

三、Spring Boot启动日志分析

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.4)//spring boot的版本

//描述spring boot应用启动所在的进程号
2021-04-11 01:03:13.568  INFO 1692 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication using Java 1.8.0_281 on 192.168.1.8 with PID 1692 (/Users/liuyu/IdeaProjects/demo/target/classes started by liuyu in /Users/liuyu/IdeaProjects/demo)
//指定加载的配置文件,这边没有指定,所以加载的是默认的
2021-04-11 01:03:13.577  INFO 1692 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
//内置tomcat运行的端口号
2021-04-11 01:03:15.066  INFO 1692 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
//启动内置tomcat
2021-04-11 01:03:15.083  INFO 1692 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-04-11 01:03:15.083  INFO 1692 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.44]
2021-04-11 01:03:15.180  INFO 1692 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-04-11 01:03:15.180  INFO 1692 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1460 ms
2021-04-11 01:03:15.460  INFO 1692 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
//tomcat启动完成,端口号8080,上下文为’‘,这里的上下文就是路径访问的项目名
2021-04-11 01:03:15.766  INFO 1692 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-04-11 01:03:15.783  INFO 1692 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 3.712 seconds (JVM running for 5.686)

四、Spring Boot的配置文件

1.配置文件默认命名为application,一般不去修改它。
2.配置文件有两种格式:properties和yml格式

例:修改tomcat服务器端口号

  • properties格式:
server.port=9090
  • yml格式:
server:
	port: 9090

五、Spring Boot应用的打包

spring boot可以打包为war包也可打包成jar包。

5.1、将应用打包成war包

打包成war包后将其丢入到外置tomcat等容器中即可启动

在这里插入图片描述

5.2、将应用打包成jar包

打包成jar包需要在pom.xml添加相应代码来告知maven需要将其打包成jar包,随后install即可。随后我们只需要使用java -jar 文件,即可运行应用。

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值