我有帶有 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
添加回答
舉報
0/150
提交
取消