Skip to content

Multiple Datasources and JPA obey Principle of Least Astonishment #10604

Closed
@cosmocracy

Description

@cosmocracy

A surprising amount of work--entirely boilerplate--is currently necessary for a Spring Boot app to utilize two (or more) Datasources with JPA. There is fantastic support for a single implicit Datasource (and autowiring it for JPA use) by configuring a handful of properties. By comparison an extraordinary amount of work--annotations and interfaces/classes--are requried to support a second Datasource with JPA (EnableTransactionManagement, EnableJpaRepositories, EntityManagerFactory, EntityManagerFactoryBuilder, PlatformTransactionManager, JpaTransactionManager, DataSourceBuilder, LocalContainerEntityManagerFactoryBean, ...)

This issue proposes that Spring Boot configuration guidelines--and supporting changes to autowiring--be developed such that adding additional Datasources for JPA doesn't require departing from a configuration-over-code mindset. The current approach certainly falls afoul of the Principle of Least Astonishment:

In general engineering design contexts, the principle can be taken to mean that a component of a system should behave in a manner consistent with how users of that component are likely to expect it to behave; that is, users should not be astonished at the way it behaves

The fact that so many developers spend time troubleshooting and discussing how to accomplish this is good evidence that a simplification is in order.

See also:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions