-
Notifications
You must be signed in to change notification settings - Fork 40.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@WebMvcTest fails with @EnableFeignClients #7270
Comments
I think I have a solution. Please take a look at PR referenced above. I've tried and this change fixed the bug. |
The underlying problem is that When Changing from I'm not sure about the best way to fix this. |
Hi I have a similar issue with new spring boot 1.5.2 with an application annotated with @EnableFeignClients I'm tring to make a test like this one:
Where SearchWithSuggestionService is a @service with 2 feign clients as dependency. When i try to run junit context fail to start with this exception:
But in stack trace i can't see any reference to ResetMocksTestExecutionListener or mockito. thanks |
Okay, I have just spent over 4 hours on this issue... Seems like there is not anything out there yet about the solution to this stuff... Here is what I did to solve this: 1. Add this annotation to your test class: @ImportAutoconfiguration({RibbonAutoConfiguration.class, FeignRibbonClientAutoConfiguration.class, FeignAutoConfiguration.class}) Try it, if it does not work, you might need the |
@Codetector1374 Thank you so much. You saved my laptop from a 10 story drop |
Why this issue is closed? Adding |
Indeed it is ugly. That's why we recommend structuring your application so that it's amenable to test slicing. In this case, that would mean avoiding the use of |
Then start with fixing documentation, actually it as easy as this: @RunWith(SpringRunner.class)
@WebMvcTest(controllers = SearchController.class) Configuration is not required at all, but it is so easy only on a paper and almost always fail in real world application.... |
Where there is information about Feign? Feign should be not included in this "slice" at all. |
That's exactly the problem. The auto-configuration that Spring Cloud provides for Feign isn't included in the slice but, due to where you've placed
If you'd like to propose something, a PR would be welcome. The javadoc of
That's an alternative solution, yes. You're now testing a single controller, rather than everything in your app that's Web MVC-related, so it's a rather different test. |
Thanks for explanation, so valid workaround is to simply create class @Configuration
@EnableFeignClients
public class CloudConfiguration {
} and removing |
@Configuration
@EnableFeignClients
public class CloudConfiguration {
} and removing This solution does not work with out using @ImportAutoconfiguration({RibbonAutoConfiguration.class, FeignRibbonClientAutoConfiguration.class, FeignAutoConfiguration.class}) |
I also had to do what @Alok86JavaPro recommended above. |
I solved this problem just by @EnableAutoConfiguration |
Solved it the same way @adramazany did, but it shouldn't be needed since |
Nothing in this thread helped |
Hi
Problem
In my app I've got a service which makes a rest call to an external API using Feign. I want to mock this external call in my @WebMvcTest by using the @MockBean annotation, but I get the following exception.
Repro steps
I've created an example project to reproduce this error. The pull request: spring-attic/spring-boot-issues#60
Temporary workaround
I was able to bypass this problem by adding to the test the feign client interface annotated with @MockBean.
The text was updated successfully, but these errors were encountered: