-
BREAKING CHANGE: Better organised DataSourceConfig to segregate Primary and Secondary data sources as per Spring Convention. Also renamed
@TargetDataSource
to@TargetSecondaryDataSource
to avoid confusion.Before:
@Configuration @EnableMultiDataSourceConfig( repositoryPackages = { "com.sample" }, exactEntityPackages = { "com.sample.project.sample_service.entities.mysql" }, dataSourceConfigs = { @DataSourceConfig(dataSourceName = "master", isPrimary = true), @DataSourceConfig(dataSourceName = "replica-2"), @DataSourceConfig(dataSourceName = "read-replica") } ) public class ServiceConfig { }
After:
@Configuration @EnableMultiDataSourceConfig( repositoryPackages = { "com.sample" }, exactEntityPackages = { "com.sample.project.sample_service.entities.mysql" }, primaryDataSourceConfig = @DataSourceConfig(dataSourceName = "master"), secondaryDataSourceConfigs = { @DataSourceConfig(dataSourceName = "replica-2"), @DataSourceConfig(dataSourceName = "read-replica") } ) public class ServiceConfig { }
-
Allow
@TargetSecondaryDataSource
to be placed on any Repository, not just JpaRepository. -
Adaptive
EntityManagerFactory
forTransactionManager
will be generated based onLocalContainerEntityManagerFactoryBean
. Decoupled from Javax/Jakarta implementations. -
Allow possibility for overriding different JPA properties for each data source by adding
@DataSourceConfig.overridingJpaPropertiesPath
field. By default, it will take the defaultspring.jpa.properties
path.
- HOTFIX: Fix
@EnableJpaRepositories.basePackages
being empty for secondary data sources when@EnableMultiDataSourceConfig.generatedRepositoryPackagePrefix
is not set. Instead, it will be set to the package of the@EnableMultiDataSourceConfig
annotated class followed by.generated.repositories
and then the snake-cased datasource name. - Default
@EnableMultiDataSourceConfig.generatedConfigPackage
changed to the package of the@EnableMultiDataSourceConfig
annotated class followed by.generated.config
instead of@EnableMultiDataSourceConfig.generatedRepositoryPackagePrefix
followed by.config
. - No repositories will be scanned for data sources which do not have a
@TargetDataSource
. - Refactor internal logic for more readability.
- BREAKING CHANGE: Configs must be defined for each data source now
under
@EnableMultiDataSourceConfig.@DataSourceConfig
. - BREAKING CHANGE:
@MultiDataSourceRepository
has been renamed to@TargetDataSource
for easier understanding. - Incremented version of Junit and Mockito.
- Restructured DataSource Level configuration for more readability and utility.
- Cosmetic improvements to generated code to include comment explaining hibernate bean container injection reasoning
- Turned utils into singleton classes instead of static classes, and enforced them with Unit Tests.
- Improved documentation
- Unit Tests added for most major elements.
- Had to use reflection for unit tests of generated Repository classes. It could be better.
- Made generated config classes abstract-able by introducing
IMultiDataSourceConfig
interface. - Some internal method name changes for consistency.
- Excluded SLF4J, even as a provided dependency, as it is not required.
- Fixed Sonatype Issues:
- Made Error Messages final static constants in a separate
class:
io.github.dhi13man.spring.datasource.constants.MultiDataSourceErrorConstants
. - Changed name of certain classes by adding
MultiDataSource
prefix to avoid name clashes in client code.
- Remove hardcoded DataSource type, and relevant legacy code for increased application-properties-based flexibility with DataSource type.
- Improvements to default code generation package config.
- Proper
isMethodSignatureMatching
check while overriding and throwing unsupported exception in base Repository methods to ensure only overriden, annotated methods are supported. - Fix Dependabot Issue #1
- Initial Release with full working implementation of @EnableMultiDataSourceConfig and @MultiDataSourceRepository
- with relevant config.
- Setup for Central Maven Repository Deployment with changed group ID and packages.
- Documentation and Guidelines.