spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.95k stars 40.65k forks source link

HibernateJpaAutoConfiguration does not back off despite LocalContainerEntityManagerFactory beans being declared manually #5542

Open odrotbohm opened 8 years ago

odrotbohm commented 8 years ago
If you remove the manual exclusion for the `HibernateJpaAutoConfiguration` [here](https://github.com/spring-projects/spring-data-examples/blob/master/jpa/multiple-datasources/src/main/java/example/springdata/jpa/multipleds/Application.java#L41) the application bootstrap will blow up trying to apply the auto configuration and failing to wire the unique `DataSource` expected to be present. I wonder why the configuration is getting applied in the first place, as I would've expected the manual declarations of `LocalContainerEntityManagerFactoryBean`s [here](https://github.com/spring-projects/spring-data-examples/blob/master/jpa/multiple-datasources/src/main/java/example/springdata/jpa/multipleds/customer/CustomerConfig.java#L51) and [here](https://github.com/spring-projects/spring-data-examples/blob/master/jpa/multiple-datasources/src/main/java/example/springdata/jpa/multipleds/order/OrderConfig.java#L51) to disable the auto-configuration in the first place.
wilkinsona commented 8 years ago

HibernateJpaAutoConfiguration creates more than just a LocalContainerEntityManagerFactoryBean so I don't think it would be appropriate for everything to back off purely because there's a user-declared LocalContainerEntityManagerFactoryBean in the context.

That said, the LocalContainerEntityManagerFactoryBean is the only auto-configured bean that depends on the DataSource so it might be possible to restructure things so that only that bean backs off when there are multiple DataSource beans in the context. That would make this a duplicate of #5541.

odrotbohm commented 8 years ago

Yeah, I've seen EntityManagerFactoryBuilder being created, which would indeed be helpful to even set up the manually declared instances. If we could untangle those parts, perfect!

wilkinsona commented 8 years ago

An interesting side-effect of isolating the auto-configuration of the LocalContainerEntityManagerFactoryBean to be the only part that requires a DataSource is that you then get various JPA-related beans being auto-configured even if there's no DataSource in the context. We could almost do with it all being conditional on at least one DataSource bean and then the LocalContainerEntityManagerFactoryBean being conditional on a single DataSource.

philwebb commented 8 years ago

This turns out to be not so easy. We'll need a bit more time to play with some ideas so it's unlikely to make 1.4.