天天看點

Spring Boot 使用 spring.datasource.data 的時候找不到資料檔案

對需要導入使用 SQL 檔案,已經放置到了 resourcesdata-trans.sql 下面了。

但是在配置的時候配置:

spring.datasource.data=data-trans.sql

顯示這個資料庫 SQL 檔案找不到。

錯誤的資訊為:

Property spring.datasource.data with value 'ServletContext resource [/data-trans.sql]' is invalid: The specified resource does not exist.

你需要将

spring.datasource.data=data-trans.sql 的檔案路徑配置參數修改為:

spring.datasource.data=classpath:data-trans.sql

spring.datasource.data=classpath:/data-trans.sql

都可以,這個主要告訴 Spring Boot 載入資料檔案的路徑。

Spring Boot 使用 spring.datasource.data 的時候找不到資料檔案
https://www.cwiki.us/display/SpringBootZH/questions/57938806