Error "There is already 'XXX' bean method" when the kotlin springmvc project runs

---Restore content begins---

1. Problems

There is a controller class in the project with a searchById method, where isLocal is a boolean parameter with a default value of false, which is used to determine whether to connect to a local or online database.

 1 @Controller
 2 @RequestMapping("api/case_info")
 3 class DocEditAction {
 4     ……
 5 
 6     @ResponseBody
 7     @RequestMapping(value = ["search"], method = [RequestMethod.GET])
 8     fun searchById(id: String, isLocal: Boolean = false): AnalyzeJson {
 9       …………
10     }    
11 
12 }

When the project is packaged as a war package and placed on tomcat, an error is reported. The error message is as follows:

public final XXX.AnalyzeJson XXX.DocEditAction.searchById(java.lang.String,boolean)
to {[/api/case_info/search],methods=[GET]}: There is already 'docEditAction' bean method
public static XXX.AnalyzeJson XXX.DocEditAction.searchById$default(XXX.DocEditAction,java.lang.String,boolean,int,java.lang.Object) mapped.
15:24:41 [http-nio-8660-exec-1] ERROR org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:502)- Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'docEditAction' method 
public final XXX.AnalyzeJson XXX.DocEditAction.searchById(java.lang.String,boolean)
to {[/api/case_info/search],methods=[GET]}: There is already 'docEditAction' bean method

The strange thing is that there are several methods with default parameters in such a controller, and no errors have been reported before. Possible related changes that occurred during this period are:

1. An old brother wrote an interceptor to process all the received requests, "requestMappingHandlerMapping" is a newly added bean

2. The kotlin version has been upgraded from 1.2.30 to 1.2.40

 

Two, the cause

I haven't found the root cause. It is speculated that there is a problem with the interceptor written by my brother.

 

3. Solutions

Write the parameters with default values ​​in the method in the method, and then repackage them and throw them into tomcat to start without reporting an error.

Although it doesn't seem to solve the underlying problem.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324884774&siteId=291194637