java -jar springboot.jar
jar支持命令行启动需要依赖maven插件支持,请确认打包时是否具有SpringBoot对应的maven插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
plugin>
plugins>
build>
jar包描述文件(MANIFEST.MF)
Manifest-Version: 1.0
Implementation-Title: springboot_08_ssmp
Implementation-Version: 0.0.1-SNAPSHOT
Build-Jdk-Spec: 1.8
Created-By: Maven Jar Plugin 3.2.0
Manifest-Version: 1.0
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
Implementation-Title: springboot_08_ssmp
Implementation-Version: 0.0.1-SNAPSHOT
Spring-Boot-Layers-Index: BOOT-INF/layers.idx
Start-Class: com.itheima. SSMPApplication
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BO0T-INF/lib/
Build-Jdk-Spec: 1.8
Spring-Boot-Version: 2.5.4
Created-By: Maven Jar Plugin 3.2.0
Main-Class: org.springframework.boot.loader.JarLauncher
#查询端口
netstat -ano
#查询指定端口
netstat -ano |findstr "端口号"
#根据进程PID查询进程名称
tasklist lfindstr "进程PID号"
# 根据PID杀死任务
taskkill /F /PID "进程PID号"
# 根据进程名称杀死任务
taskkill -f -t -im "进程名称"
java -jar springboot.jar --server.port=80
@SpringBootApplication
public class SsmpApplication {
public static void main(String[] args) {
//可以通过设置一个字符串数组的方式定义参数
String[] arg = new String[1];
arg[0] = "--server.port=8082";
SpringApplication.run(SsmpApplication.class, arg);
}
}
@SpringBootApplication
public class SsmpApplication {
public static void main(String[] args) {
//可以在启动boot程序时断开读取外部临时配置对应的入口,也就是去掉读取外部参数的形参
SpringApplication.run(SsmpApplication.class);
}
}
config/application. yml
application.yml
config/application.yml
application.yml
多配置文件常用于将配置进行分类,进行独立管理,或将可选配置单独制作便于上线更新维护
重要说明
#应用环境
spring:
profiles:
active: pro
---
#设置环境
#生产环境
spring:
config:
activate:
on-profile: pro
server:
port: 80
---
#开发环境
spring:
config:
activate:
on-profile: dev
server:
port: 81
---
#测试环境
spring:
config:
activate:
on-profile: test
server:
port: 82
application.yml
#应用环境
spring:
profiles:
active: dev
application-pro.yml
server:
port: 80
application-dev.yml
server:
port: 81
application-test.yml
server:
port: 82
application.properties
spring.profiles.active=pro
application-pro.properties
server.port=9080
application-dev.properties
server.port=9081
application-test.properties
server.port=9082
根据功能对配置文件中的信息进行拆分,并制作成独立的配置文件,命名规则如下
使用include属性在激活指定环境的情况下,同时对多个环境进行加载使其生效,多个环境间使用逗号分隔
spring:
profiles:
active:
include: devDB,devRedis,devMVC
注意事项:
当主环境dev与其他环境有相同属性时,主环境属性生效;其他环境中有相同属性时,最后加载的环境属性生效
spring:
profiles:
active: dev
group:
"dev": devMVC,devDB,devRedis
"pro": proMVC,proDB,proRedis
<profiles>
<profile>
<id>env_devid>
<properties>
<profile.active>devprofile.active>
<activation>
<activeByDefault>trueactiveByDefault>
activation>
properties>
profile>
<profile>
<id>env_proid>
<properties>
<profile.active>proprofile.active>
properties>
profile>
<profile>
<id>env_testid>
<properties>
<profile.active>testprofile.active>
properties>
profile>
profiles>
spring:
profiles:
active: @profile.active@
@RestController
@RequestMapping("/books")
public class bookController {
//创建记录日志的对象
private static final Logger log = LoggerFactory.getLogger(bookController.class);
@GetMapping
public String getById(){
System.out.println("SpringBoot is running...");
log.debug("debug.............");
log.info("info.............");
log.warn("warn.............");
log.error("error.............");
return "SpringBoot is running...";
}
}
# 开启debug模式,输出调试信息。常用于检查系统运行情况
debug:true
# 设置日志级别,root表示根节点,即整体应用日志级别
logging:
level:
root: info
logging:
#设置分组
group:
ebank: com.smulll.controller,com.smulll
iservice: com.fasterxml
level:
root: info
#设置某个包的日志级别
com.smulll.controller: debug
#设置分组,对某个分组设置日志级别
ebank: debug
<dependency>
<groupId>org.projectlombokgroupId>
<artifactId>lombokartifactId>
dependency>
@slf4j
简化开发,减少日志对象的声明操作@Slf4j
@RestController
@RequestMapping("/books")
public class bookController { @GetMapping
public String getById(){
System.out.println("SpringBoot is running...");
log.debug("debug.............");
log.info("info.............");
log.warn("warn.............");
log.error("error.............");
return "SpringBoot is running...";
}
}
logging:
pattern:
console:
logging:
pattern:
console: "%d %clr(%5p) ---[%16t] %clr(%-40.40c){cyan} : %m %n"
logging:
#设置日志文件
file:
name: server.log
logging:
#设置日志文件
file:
name: server.log
logback:
rollingpolicy:
file-name-pattern: server.%d{yyyy-MM-dd}.%i.log
max-file-size: 5KB