Purpose
This PR make spring can read annotations of param from interface or super class. It is a sample:
interface InterfaceA{
void method(@TestAnnotation String param0);
}
class ClassB implements InterfaceA{
@Override
public void method(String param0){
}
}
When you create a ClassB
bean, Spring can find TestAnnotation
from ClassB.method param0
even this method is been override.
How it work
I will scan all annotations from same signature method from interfaces and super class.
Scenarios
I think it is very usefully for feign and service. We usually create a feign project for our service(Spring MVC), like this:
@FeignClient(name = "Editor")
public interface AFeignClient {
@RequestMapping(path = "/api/test/{id}", method = RequestMethod.GET)
ResultModel getTestResult(@PathVariable("id") String id, @RequestParam(value = "paging", required = false) String paging);
As you see, we create a feign client for a API, then we will create controller from this feign client, like this:
@RestController
public class ServiceController implements AFeignClient {
@Override
ResultModel getTestResult(@PathVariable("id") String id, @RequestParam(value = "paging", required = false) String paging){
// Business code here
}
}
Yes, we don't need re-add RequestMapping
for controller, but we should re-add PathVariable
, RequestParam
...It is very easy to forget re-add annotations for controller, and IDE can't add those annotations automatically
This PR will solve this problem, you just need your controller implement FeignClient then all will be done by spring.
Comment From: pivotal-issuemaster
@higankanshi Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
Comment From: pivotal-issuemaster
@higankanshi Thank you for signing the Contributor License Agreement!
Comment From: snicoll
@higankanshi please create a Jira issue to discuss this change. Thanks!
Comment From: devkanro
@snicoll Ok, has been created(SPR-16216).
Comment From: pivotal-cla
@devkanro Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.