我檢查了類似的問題:
Spring - @Value 回傳 null
Spring Boot:@Value 始終回傳 null
然而,我找不到我的注釋有什么問題
這是代碼在 IntelliJ 的 IntelliJ螢屏截圖中的外觀
這是下面的內容
@Component
public class VisitMapper {
@Value("${spring.datasource.url}")
private String url;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
//more code below
我有兩個 .properties 檔案:application-dev.properties 和 application.properties。活動組態檔設定為 dev。在 application-dev.properties 我有:
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=postgres
不確定它是否重要,因為活動組態檔設定為 dev,但在 application.properties 中我有:
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
總結一下 - 為什么密碼值顯示為空?
uj5u.com熱心網友回復:
我懷疑 Intellij 隱藏了其中的欄位password(盡管<empty>有點蹩腳的填充物),或者 Intellij 很難為該欄位決議正確的屬性值(無論出于何種原因)。
但是,您的應用程式啟動的事實表明,至少 Spring Boot 確實正確決議了屬性,否則它不會啟動并崩潰。由于無法決議屬性或無法連接到資料庫,它不會啟動。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/362784.html
標籤:春天 PostgreSQL的 弹簧靴 注释
