Home > Back-end >  Ambiguous mapping controler class implements the interface requestmapping error Ambiguous mapping
Ambiguous mapping controler class implements the interface requestmapping error Ambiguous mapping

Time:12-19

In the use of feign a problems in the process of repeated url

If the Controller's father wrote @ RequestMapping interface method, on the Controller to realize the method of annotation @ Controller
An Ambiguous mapping,

is the key problem: my colleague start with the idea of an error in eclipse started no problem, this is very confusing

The problem code:

 
//this API is feign separation public interface
@ RequestMapping ("/customer ")
Public interface FinApi {
* new
@ RequestMapping ("/add ")
Result<?> Add (@ RequestBody FinDto FinDto) throws the Exception; }

//the following is feign server-side code
@ RestController
Public class FinController implements FinApi {
@ Override
@ Transactional
Public Result<?> Add (@ RequestBody FinConsDto FinConsDto) throws the Exception {
//execution
return null;

}}


Start an error:
 
Java. Lang. An IllegalStateException: Ambiguous mapping. Always map 'com. Customer. Controller. FinController' method
Public com. GSS. Framework. Model. Result<?> Com. Customer. Controller. FinController. Add (com) dto) FinDto) throws Java lang. Exception
The to {/customer/add} : There is already a 'finController' bean method



Solution:

Start up an annotation @ Paichu

 @ Component 
Public class MyWebMvcRegistrations implements WebMvcRegistrations {

@ Override
Public RequestMappingHandlerMapping getRequestMappingHandlerMapping () {
Return new FeignRequestMappingHandlerMapping ();
}

Private static class FeignRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
@ Override
Protected Boolean isHandler (Class<?> BeanType) {
Return super. IsHandler (beanType) & amp; & ! AnnotatedElementUtils. HasAnnotation (beanType, Paichu. Class);
}
}
}



In the process of solution of a few posts

In the way that Spring Mvc Controller class @ RequestMapping written in the book of the interface methods, then the Controller interface inheritance and realization method of @ RequestMapping will take effect as

RequestMapping Controller class methods must be written in the book of the Controller in the class?
Java | large column

CodePudding user response:

Want to ask a great god have a similar problem and then the difference between the idea and the eclipse is how cause

CodePudding user response:

You customer under global search, whether other places also have this path
  • Related