-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide an example of how to configure multiple datasources and configuration consumption #7652
Comments
That's a nice find actually. When skimmed the docs, I quickly found http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-configure-datasource scrolled through it, reached the Spring Data JPA specific bits and thought that was it. I didn't even think there could be anything further below. Linking to the HowTo from the reference section would be very helpful. |
I am looking at building the sample and some things are bugging me. I can see others in the community are confused by it. Spring Boot advertizes that we can automatically detect the driver class name based on the URL and it will automatically provide an embedded URL if no url is provided. These are pretty interesting feature but we can't cleanly apply them when one wants to configure two datasources. The main issue is that The main goal of such arrangement is to keep the auto-completion in the IDE for the custom namespaces. With the current design, a bunch of keys would be exposed that have no effect. I've start to hack something in a branch and the end-result is quite concise and only exposes the key that actually do something in practice. Still, we're not there yet. All in all, I don't think that sample can go in |
As an affected user, I'd like to comment on this discussion. I was just trying to implement a feature using two datasources. I found the documentation mentioned above, but it has two issues:
In fact, the best source I've found, was a stackoverflow posting referencing the docs and this example: https://github.com/snicoll-demos/demo-multi-entity-managers The docs should also mention, that when you configure an additional DataSource/EntityManager, the auto-configuration won't work anymore. I added a secondary DataSource+EntityManager like in the example, but now I get a warning "No bean named 'entityManagerFactory' available" and a follow-up Exception |
Thanks for the feedback. I didn't get 1. If the prefix is As of 2, I am actually keen on moving the sample from my repo to the main Spring Boot repo and reference it in the doc. |
Ah, thanks. At first, I didn't even realize it was your example I found. There seems to be duplicate issue: #3456 |
Let's focus on showing how we can "reproduce" what Boot does for us (datasource properties, initializer, etc) and how an extra datasource can be added. #7942 will avoid a cast for the second datasource. |
It seems that there are a couple of tricks needed to get a manual setup of multiple
DataSources
working nicely including the externalization of properties. Ideally the sample would show:DataSource
has its own distinct configuration.@Bean
methods to that they pick up the configuration from the declared property sets.The text was updated successfully, but these errors were encountered: