I have two Spring Boot applications which depend on the same common
module. In the common
module, I have two Configuration classes
for two different DB. In the first app, I need to have a connection on the 2 DB but in the second app is not necessary to have a connection on 2 DB and I want to have a connection only on the first DB.
My second app by default scanning the whole common
module and Configuration
for two DB
. I want to disable scanning on the second Configuration
. How can I do that?
This is my second app :
@SpringBootApplication(scanBasePackages = { "com" })
@EnableScheduling
public class secondApplication {
public static void main(String[] args) {
SpringApplication.run(secondApplication.class, args);
}
}
First configuration:
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "postgresqlEntityManagers",
transactionManagerRef = "postgresqlTransactionManager",
basePackages = "com.db1")
public class firstConfiguration {
Second Configuration:
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "postgresqlEntityManagers",
transactionManagerRef = "postgresqlTransactionManager",
basePackages = "com.db2")
public class secondConfiguration {
Based on your code, you add a @ComponnentScan
and use excludeFilters
in order to to exclude any classes you want and also exclude it from auto configuration data sources by using this @EnableAutoConfiguration
which has exclude field. by following these configurations, you should have an example as this:
@ComponentScan(basePackages = "com.example.project",
excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
classes = {AnyCustomConnectionProvider.class, AnyCustomJpaConfiguration.class}))
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
HibernateJpaAutoConfiguration.class})