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契約。問題就解決了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM