java.lang.IllegalStateException:不明确的映射。无法映射' VausRestController'方法

时间:2017-05-10 16:56:54

标签: spring-mvc spring-boot applicationcontext

我正在尝试设置仅支持1个HTTP请求的REST服务器。 我收到以下例外:

2017/05/10 16:42:46.036 ERROR:  
 Failed starting server: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'VausRestController' method 
 public org.springframework.http.ResponseEntity<com.nds.ch.vge.vaus.restController.VausRestController$ErrorResponse> com.nds.ch.vge.vaus.restController.VausRestController.signature(com.nds.ch.vge.vaus.types.EcdsaSignature)
 to {[/authentication/signature],methods=[PUT]}: There is already 'vausRestController' bean method
 public org.springframework.http.ResponseEntity<com.nds.ch.vge.vaus.restController.VausRestController$ErrorResponse> com.nds.ch.vge.vaus.restController.VausRestController.signature(com.nds.ch.vge.vaus.types.EcdsaSignature) mapped.

申请背景(相关部分):

<context:annotation-config />

<bean id="VausRestController" class="restController.VausRestController">
    <property name="authenticationManager" ref="authenticationManager" />
</bean>

代码:

import javax.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@Controller
@RestController
public class VausRestController {


    @Resource(name="authenticationManager")
    AuthenticationManager authenticationManager;

    public void setAuthenticationManager(AuthenticationManager authenticationManager) {
        this.authenticationManager = authenticationManager;
    }


    @RequestMapping(value ="/authentication/signature", method = RequestMethod.PUT)
    public ResponseEntity<Object> signature( @RequestBody final EcdsaSignature ecdsaSignature) {

        return ......
    }

请注意,我只有一个@RequestMapping。 我也尝试在我的pom.xml中更改spring版本 - 没有帮助。

1 个答案:

答案 0 :(得分:0)

这种失败的原因是在应用程序环境中&#39; bean&#39;我有大写字母id="VausRestController"

要修复,我用过:

<bean id="vausRestController" class="restController.VausRestController">
    <property name="authenticationManager" ref="authenticationManager" />
</bean>