写在前面:
继续记录自己的SpringBoot学习之旅,这次是SpringBoot应用相关知识学习记录。若看不懂则建议先看前几篇博客,详细代码可在我的Gitee仓库SpringBoot克隆下载学习使用!
本地开发的项目运行后只能运行于本地,一旦本地不运行或出问题,其它客户就无法继续进行访问,从而造成很大问题。
在本地生成一个Jar包文件,在一个远程永远运行的服务器上运行此Jar包文件,客户就可以一直访问此项目,且不受其它因素的干扰。
![![[Pasted image 20220323103342.png]]](https://1000bd.com/contentImg/2022/08/01/101720424.png)
打开打包后Jar所在文件路径并打开命令行窗口,运行指令(java -jar springboot.jar)即可,如图
![![[Pasted image 20220323105845.png]]](https://1000bd.com/contentImg/2022/08/01/101720578.png)
使用SpringBoot提供的maven插件可以将工程打包成可执行Jar包。
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
# 查询端口
netstat -ano
# 查询指定端口
netstat -ano |findstr "端口号"
# 根据进程PID查询进程名称
tasklist -ano |findstr "进程PID号"
# 根据PID杀死进程任务
taskkill /F /PID "进程PID号"
# 根据进程名称杀死进程任务
taskkill -f -t -im "进程 名称"
在启动时突然想要更改项目启动服务的端口号,可以用如下命令:
java -jar springboot*****.jar --server.port=8080
![![[Pasted image 20220406165311.png]]](https://1000bd.com/contentImg/2022/08/01/101720779.png)
![![[Pasted image 20220406170003.png]]](https://1000bd.com/contentImg/2022/08/01/101720948.png)
1级 :file(xx.jar)与config/application.yml共处同一目录下 最高
2级 :file(xx.jar)与application.yml共处同一目录下
3级 :classpath:config/application.yml
4级 :classpath:application.yml 最低
![![[Pasted image 20220406175720.png]]](https://1000bd.com/contentImg/2022/08/01/101721206.png)
![![[Pasted image 20220406180339.png]]](https://1000bd.com/contentImg/2022/08/01/101721340.png)
![![[Pasted image 20220406175742.png]]](https://1000bd.com/contentImg/2022/08/01/101721434.png)
代码如下,使用什么环境就用对应的名称
#公共配置
#应用环境
spring:
profiles:
active: pro
---
#设置环境
#生产环境
spring:
profiles: pro
server:
port: 80
---
#开发环境
#旧格式
spring:
profiles: dev
server:
port: 81
---
#测试环境
#新格式
spring:
config:
activate:
on-profile: test
server:
port: 82
![![[Pasted image 20220407114432.png]]](https://1000bd.com/contentImg/2022/08/01/101721581.png)
![![[Pasted image 20220407114538.png]]](https://1000bd.com/contentImg/2022/08/01/101721872.png)
![![[Pasted image 20220407114548.png]]](https://1000bd.com/contentImg/2022/08/01/101722104.png)
![![[Pasted image 20220407114602.png]]](https://1000bd.com/contentImg/2022/08/01/101722317.png)
spring.profiles.active=dev
server.port=80
server.port=81
server.port=82
spring:
profiles:
# active是最后加载的
active: dev
# 后加载会进行覆盖
group:
"dev": devMVC,devDB
"pro": proMVC,proDB
注:当主环境dev与其他环境有相同属性时,主环境属性生效;其他环境中有相同属性时,最后加载的属性生效
<profiles>
<profile>
<id>env_devid>
<properties>
<profile.active>devprofile.active>
properties>
<activation>
<activeByDefault>trueactiveByDefault>
activation>
profile>
<profile>
<id>env_proid>
<properties>
<profile.active>proprofile.active>
properties>
profile>
<profile>
<id>env_testid>
<properties>
<profile.active>testprofile.active>
properties>
profile>
profiles>
![![[Pasted image 20220407175233.png]]](https://1000bd.com/contentImg/2022/08/01/101722510.png)