Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Multi Module application with @SpringBootConfiguration

I have a maven multi module app with the structure :

-parent_project
-actual_project
-jpaBase

Parent project is a maven aggregation of the projects : actual_project and jpaBase (both spring boot applications)

jpaBase is a dependency of actual_project.

Now when i do a mvn package I am getting a unit test error :

Found multiple @SpringBootConfiguration annotated classes

because both jpaBase and actual_project have classes annotated with @SpringBootConfiguration.

How can I make sure that Spring considers the SpringBootConfiguration class of only actual_project and not of jpaBase.

Thanks!

like image 783
Suvrajyoti Chatterjee Avatar asked Oct 18 '25 10:10

Suvrajyoti Chatterjee


2 Answers

From the Spring documentation :

Application should only ever include one @SpringBootConfiguration and most idiomatic Spring Boot applications will inherit it from @SpringBootApplication.

You said :

because both jpaBase and actual_project have classes annotated with @SpringBootConfiguration.

It should not. This annotation has to be used a single time by application. So, only actual_project and parent_project which are Spring Boot applications should declare this annotation.

@SpringBootConfiguration replaces the declaration of these annotations:
@Configuration, @EnableAutoConfiguration and @ComponentScan

You have the information in the official documentation.

So, in your jpaBase project, you could replace @SpringBootConfiguration by the declaration of these three annotations :

@Configuration
@EnableAutoConfiguration
@ComponentScan({ "yourPackage" })
public class JpaConfig {
   ....
}
like image 89
davidxxx Avatar answered Oct 19 '25 23:10

davidxxx


Actually, for anyone looking at this, SpringBootConfiguration only replaces @Configuration.

@SpringBootApplication replaces @Configuration, @EnableAutoConfiguration and @ComponentScan.

like image 36
paulc4 Avatar answered Oct 19 '25 23:10

paulc4



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!