-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
@FeignClient with top level @RequestMapping annotation is also registered as Spring MVC handler #466
Comments
So is there some neat way to hide the @RequestMapping annotation on the interface type? |
There's no way to hide it other than not be in a web application. Or I guess put it in a child context with no handler mappings. I don't expect this will be explicitly supportable in the framework, but if you try it and it works it might be good to share your experience here. |
Closing, this would need to change in the framework. |
Does it have any new progress? |
@succour this issue is closed and we cannot fix it as this how spring framework works. |
could we not get around this by just extending the EnableWebMvcConfiguration to ignore classes annotated with @RequestMapping AND @FeignClient? Something like this? It appears to be working.
|
That's a decent workaround. I'm not sure I want that code to be in Spring Cloud though. IMO Spring MVC should not consider a bean without a |
I agree this should not exist in spring-cloud but only as a specific workaround for this issue. I also agree with your other point about @controller but that ship has sail and it would be a major breaking change to revert that now. In the mean time, we need to manage clients. IMO they are easier to maintain with the @RequestMapping annotations, and applying it at the Class level reduces the need for each method's @RequestMapping to set its consumes/produces property, making the file much easier to read and maintain. Long term, it would be great if we could delegate the isHandler method to a Bean, then spring-cloud-netflix could supply a version that takes @FeignClient into consideration to avoid the bindings. |
We have worked around it by using anotation on method only joevalerio notifications@github.com schrieb am Mi., 20. Juli 2016, 18:18:
|
What about doing: @Configuration
@ConditionalOnClass({Feign.class})
public class FeignMappingDefaultConfiguration {
@Bean
public WebMvcRegistrations feignWebRegistrations() {
return new WebMvcRegistrationsAdapter() {
@Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
return new FeignFilterRequestMappingHandlerMapping();
}
};
}
private static class FeignFilterRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
@Override
protected boolean isHandler(Class<?> beanType) {
return super.isHandler(beanType) && (AnnotationUtils.findAnnotation(beanType, FeignClient.class) == null);
}
}
} |
@kadaan thank for your code, it's working great :) |
@kadaan thank for your code. |
@kadaan thank for your code. |
@kadaan thank for your code. |
|
In my opinion this is a major security issue in spring. My application is exposing services which I call internally just because the team of the other service annotated their interfaces with @ RequestMapping on top level.
|
I guess you need to open an issue in the Spring JIRA for that? |
Can you maybe throw an error if a FeignClient also has a RequestMapping? This would at least help people who get bitten by this. |
Workaround provided by @kadaan works well when running the server but fails in Spring boot tests (FeignFilterRequestMappingHandlerMapping.isHandler is not called). |
What the progress on this? |
That's in spring Framework and not handled here, hence it was closed. Open in issue in http://jira.spring.io if you'd like |
@spencergibb Was able to reproduce this, will create issue for this on jira. Reproducible at Here is my test project for this https://github.com/Hronom/test-shared-mapping-interface |
Why not use path. Such as @FeignClient(name="localapp", path="users") |
This is follow up to the discussion from this issue: #457
Generally the problem is that: when you annotate an @FeignClient interface with @RequestMapping annotation the handler will be also registered within Spring MVC.
Example:
In this test case: jmnarloch@2d24bf6 this acctually causes the test to fail with error:
Due to duplicated Spring MVC - FeignClient mappings, but this how I found this issue.
Removing the top @RequestMapping fixes the tests, but disallows some advances usages like interface inheritance and path overriding.
The text was updated successfully, but these errors were encountered: