I have gone through the Common Application Properties reference page. This contains the list of commonly used spring props and the values of these properties can be defined in application.properties or application.yml.
So, just to explore and find out the convention regarding how and where the above props are declared (read) in java code, I started to search the code for spring-data-jpa
related properties. From this SOF answer I could see that spring.datasource.driverClassName
property is located at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
i.e at source
Similarly I want to locate the code for other properties like - spring.jpa.properties.hibernate.cache.use_query_cache
props and spring.jpa.properties.hibernate.generate_statistics
. I looked at spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm
but could not find any.
Any suggestions are highly appreciated.
I am Just trying to understand spring boot a little deeper.
Note: I could locate spring.jpa
but not the above props.
CodePudding user response:
Such behaviour is mentioned in the docs as follows :
Binding a.b=c to Map<String, String> will preserve the . in the key and return a Map with the entry {"a.b"="c"}
JpaProperties
is now defined as
@ConfigurationProperties(prefix = "spring.jpa")
public class JpaProperties {
/**
* Additional native properties to set on the JPA provider.
*/
private Map<String, String> properties = new HashMap<>();
.....
}
The prefix is spring.jpa
and this map field name is properties
. So given the following properties :
spring.jpa.properties.hibernate.cache.use_query_cache=true
spring.jpa.properties.foo=bar
will bind to this properties map with the following entries:
key=hibernate.cache.use_query_cache, value=true
key=foo, value=bar
This properties map will be directly feed into following JPA API
to create the EntityManagerFactory
:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("somePersistenceUnit", properties)
So from the spring-boot 's point of view , the values of this properties map is transparent to it. Spring boot will not care if the value in this properties map is valid or not as it just simply passes it to Hibernate to let it handle.
So if you want to know all the possible values for the properties , you have to check with hibernate source codes but not the spring-boot.