zoukankan      html  css  js  c++  java
  • 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契约。问题就解决了。

  • 相关阅读:
    循环语句 for , forin , forEach
    Haxe
    Haxe数据类型
    jango中间件的使用
    python的遍历模式
    python文件读写
    python3.5以上自带的虚拟环境在各种环境下的使用方法
    冒泡排序
    工厂方法模式
    redis 配置
  • 原文地址:https://www.cnblogs.com/sandyyeh/p/10911086.html
Copyright © 2011-2022 走看看