Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test

We Are Going To Discuss About Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test. So lets Start this Java Article.

Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test

  1. Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test

    When the Spring Boot starts, it scans the classpath from the top to the bottom of the project to find the config file. Your config is under another files and that is a reason of the problem. Move you config upper to the monolith package and everything gonna be fine.

  2. Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test

    When the Spring Boot starts, it scans the classpath from the top to the bottom of the project to find the config file. Your config is under another files and that is a reason of the problem. Move you config upper to the monolith package and everything gonna be fine.

Solution 1

src/test/java packages and src/main/java packages should match.
I had same issue where

  • my src/main/java packages were starting with com.comp.example but
  • src/test/java packages were starting with com.sample.example

Because of this spring boot application was not able to pickup the configuration of the application, which it picks up from @SpringBootApplication class.
So test case should fall under the same packages where @SpringBootApplication in src/main/java is written.

Original Author Saurabh Parmar Of This Content

Solution 2

When the Spring Boot starts, it scans the classpath from the top to the bottom of the project to find the config file. Your config is under another files and that is a reason of the problem. Move you config upper to the monolith package and everything gonna be fine.

Original Author Yuriy Tsarkov Of This Content

Solution 3

@SpringBootTest has a parameter named classes. It accepts an array of classes for configuration. Add the class for the config file to it, for example:

@SpringBootTest(classes={com.lapots.game.monolith.web.GrandJourneyMonolithApplication.class})

Original Author downeyt Of This Content

Solution 4

The Test src/test/java files should also follow the same directory structure as in src/main/java.

enter image description here

Original Author pankaj pundir Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment