SpringBoot配置
SpringBoot——03配置
YAML:Springboot除了支持properties的配置,还支持yaml(音译“雅梅尔”),而且目前企业中也是比较常用的。

YAML是便于人阅读基于unicode编码的各种语言的***标准。它的用途广泛,用于配置文件,日志文件,跨语言数据共享,对象持久化,复杂的数据结构。

YAML原则:

大小写敏感
使用缩进表示层级关系
缩进长度没有限制,只要元素对齐就表示这些元素属于一个层级。
使用#表示注释
字符串可以不用引号标注

application.yml

server:
  port: 9001
spring:
  freemarker:
    allow-request-override: false
    cache: false
    check-template-location: true
    charset: utf-8
    content-type: text/html
    expose-request-attributes: false
    expose-session-attributes: false
    expose-spring-macro-helpers: false

模块结构:
SpringBoot——03配置
springboot运行方式:

     开发时:在idea中直接通过main函数启动

     测试时:jar运行

     项目上线时:jar运行

	 环境不同解决办法:Spring Profiles多环境支持

Spring Profiles提供了一种隔离应用程序配置的方式,并让这些配置只在特定的环境下生效

配置多个环境——>运行时执行特定环境

spring:
  profiles:
    active: dev
---
spring:
     profiles: dev
---
spring:
  profiles: test
---
spring:
  profiles: prod

打包,命令:mvn clean package spring-boot:repackage
SpringBoot——03配置
注:打包成功后查看springboot_04_config-1.0-SNAPSHOT.jar\META-INF中的MANIFEST.MF文件有没有入口
SpringBoot——03配置
运行,命令:java -jar -Dspring.profiles.active=dev xxx.jar
注:**指定profile 加 -Dspring.profiles.active=dev
SpringBoot——03配置

相关文章:

  • 2022-01-21
  • 2021-05-08
  • 2021-09-27
  • 2021-10-20
  • 2021-09-10
  • 2021-09-18
  • 2022-12-23
  • 2021-07-15
猜你喜欢
  • 2021-04-26
  • 2021-08-07
  • 2022-12-23
  • 2021-07-03
  • 2021-11-14
  • 2022-01-03
相关资源
相似解决方案