All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.dhi13man.spring.datasource.annotations.TargetSecondaryDataSource Maven / Gradle / Ivy

Go to download

To mitigate Spring's limitations with multiple data sources in a single service, this library provides two custom annotations in Java that automatically generate all the required bean definition configurations and package-segregated repositories, for each data source.

The newest version!
package io.github.dhi13man.spring.datasource.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;

/**
 * Annotation to create copies of the repositories in the relevant packages, and autoconfigure them
 * to use the relevant secondary data sources.
 * 

* Will generate all relevant boilerplate code and beans. */ @Target({ElementType.METHOD}) @Retention(RetentionPolicy.CLASS) @Repeatable(TargetSecondaryDataSources.class) public @interface TargetSecondaryDataSource { /** * Alias for dataSourceName, the name of the data source to use for the repository. *

* To use a data source other than the primary, it must have been configured in the * {@link EnableMultiDataSourceConfig#secondaryDataSourceConfigs()} annotations. *

* The generated repositories will be placed in the same package as the class annotated with * {@link EnableMultiDataSourceConfig} followed by .generated.repositories and then * .{snake_case_data_source_name} *

* The generated repositories will be placed in packages with the following format: *

* {generatedRepositoryPackagePrefix}.{PascalCaseDataSourceName}{AnnotatedMethodRepositoryName} * * @return the data source to use for the repository. * @see EnableMultiDataSourceConfig.DataSourceConfig#dataSourceName() */ @AliasFor("dataSourceName") String value() default "replica"; }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy