SpringBoot2.4中profile include後不生效的解決方法
阿新 • • 發佈:2020-12-30
技術標籤:javaSpringBoot
背景提要
使用SpringInitializer建立新專案後,使用原專案中的程式碼結構對專案進行初始化,其中springProfile包含關係如下:
application.yml include: repository,service,web active: dev application-dev.yml include: repository-dev,service-dev,web-dev application-release.yml include: repository-release,service-release,web-release
發現啟動時報錯說找不到資料庫配置
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (the profiles dev,repository,service,web are currently active).
經查發現springBoot2.4對配置檔案的載入做了更新
解決方法
強制spring使用原載入方式載入配置檔案
需要在application.yml中增加如下配置
spring:
config:
use-legacy-processing: true
WIKI中解釋如下:
使用profile group管理配置檔案
spring:
application:
name: sc_server_user
profiles:
group:
"dev": "repository-dev,service-dev,web-dev"
"release" : "repository-release,web-release,service-release"
active: @[email protected]
include: "repository,service,web"
詳見上述官方WIKI!