为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用 spring boot + .yaml 创建配置文件?

如何使用 spring boot + .yaml 创建配置文件?

呼唤远方 2021-10-27 09:56:13
我有带有 2 个属性文件的 Spring Boot 服务器:application-local.properties和application-test.properties在每个文件中,我都有用于开发机器和测试的配置。像这样开始:-Dspring.profiles.active=local但是在新的 Spring Boot 项目中,我使用了.yaml配置文件。而且我不明白如何使用profileswith .yaml. 我尝试阅读文档,但什么也不懂。你能一步一步解释该怎么做吗?我需要两个文件?application-local.yaml 和 application-test.yaml或者我需要在一个application.yaml文件中写入所有内容?如果在一个文件中,我如何分离配置?这是我的配置:server:  path: ***  port: ***cxf:  path: ***spring.datasource:  type: com.zaxxer.hikari.HikariDataSource  driver-class-name: oracle.jdbc.OracleDriver  url: ***  username: ***  password: ***  hikari:    minimumIdle: 5    maximumPoolSize: 20    idleTimeout: 30000    poolName: SpringBootJPAHikariCP    maxLifetime: 2000000    connectionTimeout: 30000    connection-test-query: SELECT 1 FROM DUALspring.jpa:  show-sql: false  database-platform: org.hibernate.dialect.Oracle10gDialect  properties.hibernate.jdbc.batch_size: 30  properties.hibernate.cache.use_second_level_cache: false  hibernate:    ddl-auto: validatespring.cache:  ehcache:    config: classpath:ehcache.xml#app configsmy:  messages-max-count: 5  messages-delay: 100  schedulers-charge-delay: 100  client:    first-server-address: ***    second-server-address: ***    last-server-address: ***  enabled-client: FirstClient我想创建测试配置文件并更改数据库 url(或更改为 postgreSql),更改maximumPoolSize属性
查看完整描述

2 回答

?
HUH函数

TA贡献1836条经验 获得超4个赞

是的,即使使用单个文件,您也可以创建多个配置文件配置文件用 3 个 DASH ( --- )分隔


logging:

  level:

    .: error

    org.springframework: ERROR


spring:

  profiles:

    active: "dev"

  main:

    banner-mode: "off"


server:

  port: 8085


---


spring:

  profiles: dev


---


spring:

  profiles: prod


查看完整回答
反对 回复 2021-10-27
  • 2 回答
  • 0 关注
  • 204 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信