4

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!

1
  • Is jpaBase an actual application which needs to run independently or just the persistence layer for your actual_project? Commented Dec 11, 2016 at 19:17

2 Answers 2

5

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 {
   ....
}
Sign up to request clarification or add additional context in comments.

1 Comment

The build was failing after replacing the SpringBootApplication annotation for the jpaBase project, as now it wasn't able to find any SpringBootApplication clsas for jpaBase. But based on your suggestion I have now removed jpaBase as a SpringBootApplication by moving the SpringBootDependencies from the parent project section to dependency management section in the parent_project pom. It works now
1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.