Context: Using Spring Boot 0.5.0-M7, MySQL and Commons DBCP, Java config, @EnableAutoConfiguration
set.
I have defined the application's DataSource
bean, JpaVendorAdapter
bean, LocalContainerEntityManagerFactoryBean
and TransactionManager
beans with specific configuration to support DBCP and some Hibernate settings. On application startup, the DataSource
is definitely being respected (debug confirms), but the other beans are ignored. This appears to be as a result of the JpaBaseConfiguration
class, which is brought into the mix by the WebMvcConfiguration
and one of it's Security Filters. In any case, among other things the issue is that the Hibernate setting sets the hbm2ddl (Schema export) to drop-create
, such that I lose my data every time the server restarts.
I looked through the source and found that there appears to be affordance to set Environment variables that will be respected in the JpaBaseConfiguration
, however that seems to defeat setting up beans to do the same job. I have tried excluding some autoconfiguration classes related to Data to no avail. Is there some other expectation for setting up a non-default data configuration I may be missing?
Spring Boot application converts the command line properties into Spring Boot Environment properties. Command line properties take precedence over the other property sources. By default, Spring Boot uses the 8080 port number to start the Tomcat.
Spring has always favoured convention over configuration, which means it takes up the majority of working uses cases into consideration and goes by it rather than nit-picking an exact configuration and dependencies required for a specific application development.
To override your Spring Boot application properties when it's running on Kubernetes, just set environment variables on the container. To set an environment variable on a container, first, initialise a ConfigMap containing the environment variables that you want to override.
Configuring Spring Data JPA We can configure Spring Data JPA by following these steps: Enable Spring Data JPA by annotating the PersistenceContext class with the @EnableJpaRepositories annotation. Configure the base packages that are scanned when Spring Data JPA creates implementations for our repository interfaces.
Looking at the code for Spring Boot 0.5.0.M7 when hibernate is detected (HibernateEntityManager
) and Springs LocalContainerEntityManagerFactoryBean
hibernate will always be configured by default. You can override certain properties by putting them in the application.properties.
spring.jpa.hibernate.naming-strategy
- Will set the naming-strategy used default = ImprovedNamingStrategy
.
spring.jpa.hibernate.ddl-auto
- will set the hibernate.hbm2ddl.auto default = create-drop.
General JPA properties you can set
spring.jpa.show-sql
- show sql in the logsspring.jpa.database-platform
- for hibernate this is the dialectspring.jpa.database
- The database used (don't use together with database-platform!).spring.jpa.generate-ddl
- should the ddl be generated, default false (overriden by the spring.jpa.hibernate.ddl-auto
property)If you want to speficy some none default properties prefix them with spring.jpa.properties
then they will be added to the jpaProperties
of the LocalContainterEntityManagerFactoryBean
.
The inclusion of the HibernateJpaAutoConfiguration
isn't related to any other configuration it is simply triggered by the detected of the some classes
@ConditionalOnClass({ LocalContainerEntityManagerFactoryBean.class,
EnableTransactionManagement.class, EntityManager.class,
HibernateEntityManager.class })
@ConditionalOnBean(DataSource.class)
@EnableTransactionManagement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With