Spring boot 1.4 Testing : Configuration error: found multiple declarations of @BootstrapWith Spring boot 1.4 Testing : Configuration error: found multiple declarations of @BootstrapWith spring spring

Spring boot 1.4 Testing : Configuration error: found multiple declarations of @BootstrapWith


This exception occurs when spring test can not find main configuration class.Try to add @ContextConfiguration anootation to your test class. Follow the spring test documention for more details (section Detecting test configuration)

My example Test class is like this:

@RunWith(SpringRunner.class)@ContextConfiguration(classes=Application.class)@WebMvcTest(MyController.class)public class MyConrollerTests {    ...}


Just Remove the @SpringBootTest and everything work fine. I had the same problem with using @SpringBootTest and @DataJpaTest, this error raised when I upgraded the pom.xml parent springboot version to 2.1.0 as below. When I was using version 2.0.5, this error was not raising.

@RunWith(SpringRunner.class)//@SpringBootTest//(classes = KalahApplication.class)// DataJpaTest supports rollback after running every test case@DataJpaTestpublic class GameRepositoryTest {

pom.xml

   <parent>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-parent</artifactId>        <version>2.1.0.RELEASE</version>        <relativePath/> <!-- lookup parent from repository -->   </parent>


I know its too late to answer this question, but it may help someone in the future so... I had the same issue and after some research, i found that there shouldn't be @WebMvcTest if there is @SpringBootTest. so just remove @WebMvcTest and @SpringBootTest is taking care of the rest.