java.lang.IllegalStateException: Method get not annotated with HTTP method type (ex. GET, POST);

明明指定了请求方法类型还报错:

代码:

@RequestMapping(value="/enterprise/detail",method = RequestMethod.POST,consumes = MediaType.APPLICATION_JSON_VALUE)
ResponseMsg get(@RequestBody RequestMsg req);

异常信息:

java.lang.IllegalStateException: Method get not annotated with HTTP method type (ex. GET, POST);

网上好多这个异常的是加POST GET方法。但我这个是加了的。为什么呢?这个时候就要想底层的契约了。

Fegin配置文件是这样的:

@Configuration
public class FeignClientUserServiceConfiguration {
    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }

    @Bean
    public Contract feignContract() {
        return new feign.Contract.Default();
    }

    @Bean
    public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
        return new BasicAuthRequestInterceptor("user", "password");
    }    
}

红色部分显示项目用的是fegin的契约。

默认契约用的是@RequestLine注解。RequestLine 如果不知名POST还是GET 就会报 Method get not annotated with HTTP method type (ex. GET, POST)。

那如果要用@RequestMapping 注解怎么办呢,把上面的红色部分的配置删掉,那样Fegin会使用SpringMvcContract契约。问题就解决了。

猜你喜欢

转载自www.cnblogs.com/sandyyeh/p/10911086.html
今日推荐