我已經瀏覽了Common Application Properties參考頁面。這包含了常用的 spring props 串列,這些屬性的值可以在 application.properties 或 application.yml 中定義。
因此,只是為了探索和找出有關在 Java 代碼中宣告(讀取)上述 props 的方式和位置的約定spring-data-jpa,我開始在代碼中搜索相關屬性。從這個SOF 答案中,我可以看到該spring.datasource.driverClassName屬性位于org.springframework.boot.autoconfigure.jdbc.DataSourcePropertiesie 在源
同樣,我想找到其他屬性的代碼,例如 - spring.jpa.properties.hibernate.cache.use_query_cacheprops 和spring.jpa.properties.hibernate.generate_statistics. 我看了看,spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm但找不到。
任何建議都受到高度贊賞。
我只是想更深入地了解彈簧靴。
注意:我可以找到spring.jpa但不能找到上述道具。
uj5u.com熱心網友回復:
這種行為在檔案中提到如下:
將 ab=c 系結到 Map<String, String> 將保留 . 在鍵中并回傳一個帶有條目 {"ab"="c"} 的 Map
JpaProperties現在定義為
@ConfigurationProperties(prefix = "spring.jpa")
public class JpaProperties {
/**
* Additional native properties to set on the JPA provider.
*/
private Map<String, String> properties = new HashMap<>();
.....
}
前綴是spring.jpa,此地圖欄位名稱是properties。所以給定以下屬性:
spring.jpa.properties.hibernate.cache.use_query_cache=true
spring.jpa.properties.foo=bar
將使用以下條目系結到此屬性映射:
key=hibernate.cache.use_query_cache, value=true
key=foo, value=bar
此屬性映射將直接輸入以下內容JPA API以創建EntityManagerFactory:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("somePersistenceUnit", properties)
所以從 spring-boot 的角度來看,這個屬性映射的值對它是透明的。Spring boot 不會關心這個屬性映射中的值是否有效,因為它只是簡單地將它傳遞給 Hibernate 讓它處理。
因此,如果您想知道 properties 的所有可能值,則必須檢查 hibernate 源代碼,而不是 spring-boot。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/524357.html
標籤:爪哇春天弹簧靴jpa
