Spring boot 1.4 Testing : Configuration error: found multiple declarations of @BootstrapWith
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
add a comment |
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
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
add a comment |
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
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
java spring spring-mvc spring-boot spring-test
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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 {
...
}
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
add a comment |
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>
add a comment |
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.
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 {
...
}
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
add a comment |
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 {
...
}
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
add a comment |
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 {
...
}
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 {
...
}
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
add a comment |
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
add a comment |
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>
add a comment |
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>
add a comment |
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>
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>
answered Nov 20 '18 at 0:16
NesrinNesrin
7315
7315
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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