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












16















By following the official doc here:
http://docs.spring.io/spring-boot/docs/1.4.0.M2/reference/htmlsingle/#Testing



i wanted to test one of my REST API method like this:



@RunWith(SpringRunner.class)
@WebMvcTest(LoginController.class)
@SpringBootTest(classes = Application.class)
public class AuthorizationServiceTest {
@Autowired
private TestRestTemplate restTemplate;

@Test
public void test() {
Object returnedObject=his.restTemplate.getForObject("/login", Object.class);
}
}


As stated in the doc :




The search algorithm works up from the package that contains the test
until it finds a @SpringBootApplication or @SpringBootConfiguration
annotated class. As long as you’ve structure your code in a sensible
way your main configuration is usually found.




I have structured my code properly(atleast i think ):



AuthorizationService : is under package com.xxx.yyy.zzz.authorization;



AuthorizationServiceTest : is under package com.xxx.yyy.zzz.authorizationTest;



I am getting this exception(Full Trace):



java.lang.IllegalStateException: Configuration error: found multiple declarations of @BootstrapWith for test class [com.orangeraid.rasberry.gateway.authorizationTest.AuthorizationServiceTest]: [@org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper), @org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.context.SpringBootTestContextBootstrapper)]
at org.springframework.test.context.BootstrapUtils.resolveExplicitTestContextBootstrapper(BootstrapUtils.java:155)
at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:126)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:105)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:152)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:143)
at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


Please help me with this, i have already spent more than 2-3 hours without any luck.



Thanks.










share|improve this question




















  • 14





    @SpringBootTest and @WebMvcTest are mutually exclusive... Either you test the whole application or you test a slice but not both.

    – M. Deinum
    Dec 9 '16 at 9:56






  • 2





    @M.Deinum : its big hint, thanks

    – lesnar
    Dec 9 '16 at 10:03











  • I had a similar problem with both @SpringBootTest and @DataMongoTest. Removing @SpringBootTest solved the problem. The error message could be clearer though...

    – Olivier Gérardin
    Nov 19 '18 at 9:37


















16















By following the official doc here:
http://docs.spring.io/spring-boot/docs/1.4.0.M2/reference/htmlsingle/#Testing



i wanted to test one of my REST API method like this:



@RunWith(SpringRunner.class)
@WebMvcTest(LoginController.class)
@SpringBootTest(classes = Application.class)
public class AuthorizationServiceTest {
@Autowired
private TestRestTemplate restTemplate;

@Test
public void test() {
Object returnedObject=his.restTemplate.getForObject("/login", Object.class);
}
}


As stated in the doc :




The search algorithm works up from the package that contains the test
until it finds a @SpringBootApplication or @SpringBootConfiguration
annotated class. As long as you’ve structure your code in a sensible
way your main configuration is usually found.




I have structured my code properly(atleast i think ):



AuthorizationService : is under package com.xxx.yyy.zzz.authorization;



AuthorizationServiceTest : is under package com.xxx.yyy.zzz.authorizationTest;



I am getting this exception(Full Trace):



java.lang.IllegalStateException: Configuration error: found multiple declarations of @BootstrapWith for test class [com.orangeraid.rasberry.gateway.authorizationTest.AuthorizationServiceTest]: [@org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper), @org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.context.SpringBootTestContextBootstrapper)]
at org.springframework.test.context.BootstrapUtils.resolveExplicitTestContextBootstrapper(BootstrapUtils.java:155)
at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:126)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:105)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:152)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:143)
at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


Please help me with this, i have already spent more than 2-3 hours without any luck.



Thanks.










share|improve this question




















  • 14





    @SpringBootTest and @WebMvcTest are mutually exclusive... Either you test the whole application or you test a slice but not both.

    – M. Deinum
    Dec 9 '16 at 9:56






  • 2





    @M.Deinum : its big hint, thanks

    – lesnar
    Dec 9 '16 at 10:03











  • I had a similar problem with both @SpringBootTest and @DataMongoTest. Removing @SpringBootTest solved the problem. The error message could be clearer though...

    – Olivier Gérardin
    Nov 19 '18 at 9:37
















16












16








16


4






By following the official doc here:
http://docs.spring.io/spring-boot/docs/1.4.0.M2/reference/htmlsingle/#Testing



i wanted to test one of my REST API method like this:



@RunWith(SpringRunner.class)
@WebMvcTest(LoginController.class)
@SpringBootTest(classes = Application.class)
public class AuthorizationServiceTest {
@Autowired
private TestRestTemplate restTemplate;

@Test
public void test() {
Object returnedObject=his.restTemplate.getForObject("/login", Object.class);
}
}


As stated in the doc :




The search algorithm works up from the package that contains the test
until it finds a @SpringBootApplication or @SpringBootConfiguration
annotated class. As long as you’ve structure your code in a sensible
way your main configuration is usually found.




I have structured my code properly(atleast i think ):



AuthorizationService : is under package com.xxx.yyy.zzz.authorization;



AuthorizationServiceTest : is under package com.xxx.yyy.zzz.authorizationTest;



I am getting this exception(Full Trace):



java.lang.IllegalStateException: Configuration error: found multiple declarations of @BootstrapWith for test class [com.orangeraid.rasberry.gateway.authorizationTest.AuthorizationServiceTest]: [@org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper), @org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.context.SpringBootTestContextBootstrapper)]
at org.springframework.test.context.BootstrapUtils.resolveExplicitTestContextBootstrapper(BootstrapUtils.java:155)
at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:126)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:105)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:152)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:143)
at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


Please help me with this, i have already spent more than 2-3 hours without any luck.



Thanks.










share|improve this question
















By following the official doc here:
http://docs.spring.io/spring-boot/docs/1.4.0.M2/reference/htmlsingle/#Testing



i wanted to test one of my REST API method like this:



@RunWith(SpringRunner.class)
@WebMvcTest(LoginController.class)
@SpringBootTest(classes = Application.class)
public class AuthorizationServiceTest {
@Autowired
private TestRestTemplate restTemplate;

@Test
public void test() {
Object returnedObject=his.restTemplate.getForObject("/login", Object.class);
}
}


As stated in the doc :




The search algorithm works up from the package that contains the test
until it finds a @SpringBootApplication or @SpringBootConfiguration
annotated class. As long as you’ve structure your code in a sensible
way your main configuration is usually found.




I have structured my code properly(atleast i think ):



AuthorizationService : is under package com.xxx.yyy.zzz.authorization;



AuthorizationServiceTest : is under package com.xxx.yyy.zzz.authorizationTest;



I am getting this exception(Full Trace):



java.lang.IllegalStateException: Configuration error: found multiple declarations of @BootstrapWith for test class [com.orangeraid.rasberry.gateway.authorizationTest.AuthorizationServiceTest]: [@org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper), @org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.context.SpringBootTestContextBootstrapper)]
at org.springframework.test.context.BootstrapUtils.resolveExplicitTestContextBootstrapper(BootstrapUtils.java:155)
at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:126)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:105)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:152)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:143)
at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


Please help me with this, i have already spent more than 2-3 hours without any luck.



Thanks.







java spring spring-mvc spring-boot spring-test






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 4 '18 at 11:11







lesnar

















asked Dec 9 '16 at 9:54









lesnarlesnar

84042048




84042048








  • 14





    @SpringBootTest and @WebMvcTest are mutually exclusive... Either you test the whole application or you test a slice but not both.

    – M. Deinum
    Dec 9 '16 at 9:56






  • 2





    @M.Deinum : its big hint, thanks

    – lesnar
    Dec 9 '16 at 10:03











  • I had a similar problem with both @SpringBootTest and @DataMongoTest. Removing @SpringBootTest solved the problem. The error message could be clearer though...

    – Olivier Gérardin
    Nov 19 '18 at 9:37
















  • 14





    @SpringBootTest and @WebMvcTest are mutually exclusive... Either you test the whole application or you test a slice but not both.

    – M. Deinum
    Dec 9 '16 at 9:56






  • 2





    @M.Deinum : its big hint, thanks

    – lesnar
    Dec 9 '16 at 10:03











  • I had a similar problem with both @SpringBootTest and @DataMongoTest. Removing @SpringBootTest solved the problem. The error message could be clearer though...

    – Olivier Gérardin
    Nov 19 '18 at 9:37










14




14





@SpringBootTest and @WebMvcTest are mutually exclusive... Either you test the whole application or you test a slice but not both.

– M. Deinum
Dec 9 '16 at 9:56





@SpringBootTest and @WebMvcTest are mutually exclusive... Either you test the whole application or you test a slice but not both.

– M. Deinum
Dec 9 '16 at 9:56




2




2





@M.Deinum : its big hint, thanks

– lesnar
Dec 9 '16 at 10:03





@M.Deinum : its big hint, thanks

– lesnar
Dec 9 '16 at 10:03













I had a similar problem with both @SpringBootTest and @DataMongoTest. Removing @SpringBootTest solved the problem. The error message could be clearer though...

– Olivier Gérardin
Nov 19 '18 at 9:37







I had a similar problem with both @SpringBootTest and @DataMongoTest. Removing @SpringBootTest solved the problem. The error message could be clearer though...

– Olivier Gérardin
Nov 19 '18 at 9:37














3 Answers
3






active

oldest

votes


















14














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 {
...
}





share|improve this answer
























  • Worked perfectly!

    – Kaushal28
    Feb 2 '18 at 8:38











  • Note: This is also necessary if you move the Application.class from the default main package to a sub-package.

    – rwenz3l
    Aug 1 '18 at 11:45











  • Also fixes the 2 application classes issue when you have one separate for tests.

    – milosmns
    Dec 6 '18 at 11:59



















6














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
@DataJpaTest
public 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>





share|improve this answer































    0














    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.






    share|improve this answer
























    • From the documentation: In this test, the full Spring application context is started, but without the server. We can narrow down the tests to just the web layer by using @WebMvcTest Which means @WebMvcTest is useful to make tests a bit lighter by not loading a server neither a full application context. Thus Nesrin's answer is more accurate.

      – Sidney de Moraes
      Feb 5 at 17:34











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41057602%2fspring-boot-1-4-testing-configuration-error-found-multiple-declarations-of-b%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    14














    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 {
    ...
    }





    share|improve this answer
























    • Worked perfectly!

      – Kaushal28
      Feb 2 '18 at 8:38











    • Note: This is also necessary if you move the Application.class from the default main package to a sub-package.

      – rwenz3l
      Aug 1 '18 at 11:45











    • Also fixes the 2 application classes issue when you have one separate for tests.

      – milosmns
      Dec 6 '18 at 11:59
















    14














    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 {
    ...
    }





    share|improve this answer
























    • Worked perfectly!

      – Kaushal28
      Feb 2 '18 at 8:38











    • Note: This is also necessary if you move the Application.class from the default main package to a sub-package.

      – rwenz3l
      Aug 1 '18 at 11:45











    • Also fixes the 2 application classes issue when you have one separate for tests.

      – milosmns
      Dec 6 '18 at 11:59














    14












    14








    14







    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 {
    ...
    }





    share|improve this answer













    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 {
    ...
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Apr 27 '17 at 13:28









    mahkrasmahkras

    14116




    14116













    • Worked perfectly!

      – Kaushal28
      Feb 2 '18 at 8:38











    • Note: This is also necessary if you move the Application.class from the default main package to a sub-package.

      – rwenz3l
      Aug 1 '18 at 11:45











    • Also fixes the 2 application classes issue when you have one separate for tests.

      – milosmns
      Dec 6 '18 at 11:59



















    • Worked perfectly!

      – Kaushal28
      Feb 2 '18 at 8:38











    • Note: This is also necessary if you move the Application.class from the default main package to a sub-package.

      – rwenz3l
      Aug 1 '18 at 11:45











    • Also fixes the 2 application classes issue when you have one separate for tests.

      – milosmns
      Dec 6 '18 at 11:59

















    Worked perfectly!

    – Kaushal28
    Feb 2 '18 at 8:38





    Worked perfectly!

    – Kaushal28
    Feb 2 '18 at 8:38













    Note: This is also necessary if you move the Application.class from the default main package to a sub-package.

    – rwenz3l
    Aug 1 '18 at 11:45





    Note: This is also necessary if you move the Application.class from the default main package to a sub-package.

    – rwenz3l
    Aug 1 '18 at 11:45













    Also fixes the 2 application classes issue when you have one separate for tests.

    – milosmns
    Dec 6 '18 at 11:59





    Also fixes the 2 application classes issue when you have one separate for tests.

    – milosmns
    Dec 6 '18 at 11:59













    6














    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
    @DataJpaTest
    public 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>





    share|improve this answer




























      6














      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
      @DataJpaTest
      public 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>





      share|improve this answer


























        6












        6








        6







        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
        @DataJpaTest
        public 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>





        share|improve this answer













        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
        @DataJpaTest
        public 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>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 0:16









        NesrinNesrin

        7315




        7315























            0














            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.






            share|improve this answer
























            • From the documentation: In this test, the full Spring application context is started, but without the server. We can narrow down the tests to just the web layer by using @WebMvcTest Which means @WebMvcTest is useful to make tests a bit lighter by not loading a server neither a full application context. Thus Nesrin's answer is more accurate.

              – Sidney de Moraes
              Feb 5 at 17:34
















            0














            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.






            share|improve this answer
























            • From the documentation: In this test, the full Spring application context is started, but without the server. We can narrow down the tests to just the web layer by using @WebMvcTest Which means @WebMvcTest is useful to make tests a bit lighter by not loading a server neither a full application context. Thus Nesrin's answer is more accurate.

              – Sidney de Moraes
              Feb 5 at 17:34














            0












            0








            0







            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.






            share|improve this answer













            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.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 3 at 5:35









            jaliljalil

            627




            627













            • From the documentation: In this test, the full Spring application context is started, but without the server. We can narrow down the tests to just the web layer by using @WebMvcTest Which means @WebMvcTest is useful to make tests a bit lighter by not loading a server neither a full application context. Thus Nesrin's answer is more accurate.

              – Sidney de Moraes
              Feb 5 at 17:34



















            • From the documentation: In this test, the full Spring application context is started, but without the server. We can narrow down the tests to just the web layer by using @WebMvcTest Which means @WebMvcTest is useful to make tests a bit lighter by not loading a server neither a full application context. Thus Nesrin's answer is more accurate.

              – Sidney de Moraes
              Feb 5 at 17:34

















            From the documentation: In this test, the full Spring application context is started, but without the server. We can narrow down the tests to just the web layer by using @WebMvcTest Which means @WebMvcTest is useful to make tests a bit lighter by not loading a server neither a full application context. Thus Nesrin's answer is more accurate.

            – Sidney de Moraes
            Feb 5 at 17:34





            From the documentation: In this test, the full Spring application context is started, but without the server. We can narrow down the tests to just the web layer by using @WebMvcTest Which means @WebMvcTest is useful to make tests a bit lighter by not loading a server neither a full application context. Thus Nesrin's answer is more accurate.

            – Sidney de Moraes
            Feb 5 at 17:34


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41057602%2fspring-boot-1-4-testing-configuration-error-found-multiple-declarations-of-b%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Why https connections are so slow when debugging (stepping over) in Java?