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契约。问题就解决了。

原文地址:https://www.cnblogs.com/sandyyeh/p/10911086.html

时间: 2024-08-12 03:11:49

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

java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration$ThymeleafDefaultConfiguration.templateEngine

2018-12-25 22:58:28.023 DEBUG 2204 --- [ restartedMain] c.c.c.a.CrawlerAutohomeApplication : Running with Spring Boot v2.1.1.RELEASE, Spring v5.1.3.RELEASE 2018-12-25 22:58:28.039 INFO 2204 --- [ restartedMain] c.c.c.a.CrawlerAutohomeApplication : No

异常:java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path '/app/userInfoMaint/getProvince.do'

调试代码时出现异常:java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path '/app/userInfoMaint/getProvince.do':当时就郁闷了,好像之前没怎么见过,后来发现原来是后台有两个"app/userInfoMaint/getProvince.do",并且它们路径相同. 解决方法很简单,相信大家都知道,就是将后台两个方法请求路径名区分开. 由上可知,锁定问题是

Android 学习之异常总结--java.lang.IllegalStateException:Could not execute method of the activity

在android学习过程中通常会遇到java.lang.IllegalStateException:Could not execute method of the activity这个错误:非法状态的异常 往android的主程序去写东西的时候必须要拿到上下文的,调用普通对象的方法是没有上下文的.

【异常】Caused by: java.lang.IllegalStateException: Method has too many Body parameters

出现此异常原因是引文使用feign客户端的时候,参数没有用注解修饰 1.1GET方式错误写法 @RequestMapping(value="/test", method=RequestMethod.GET) Model test(final String name, final int age); 启动服务的时候,会报如下异常: Caused by: java.lang.IllegalStateException: Method has too many Body parameters

caused by: java.lang.IllegalStateException: Method has too many Body parameters: 多参数问题

https://blog.csdn.net/liuchuanhong1/article/details/54728681 多参数问题 @RequestMapping(value="/user/name", method=RequestMethod.GET)   User findByUsername(final String userName, final String address); 启动服务的时候,会报如下异常: Caused by: java.lang.IllegalStat

java.lang.IllegalStateException: Failed to load ApplicationContext

1.错误描述 INFO:2015-02-05 22:14:21[main] - Loading XML bean definitions from class path resource [applicationContext.xml] INFO:2015-02-05 22:14:22[main] - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning INFO:2015-02-05

使用printWrite 在jetty中报错 java.lang.IllegalStateException: STREAM

1 public void doFilter(ServletRequest request, ServletResponse response, 2 FilterChain chain) throws IOException, ServletException { 3 // TODO Auto-generated method stub 4 HttpServletRequest req=(HttpServletRequest)request; 5 HttpServletResponse res=

WARN::Committed before 500 Unable to show problem report:|java.lang.IllegalStateException

2015-01-06 18:23:17.160:WARN::Committed before 500 Unable to show problem report:|java.lang.IllegalStateException: STREAM||Class: org.mortbay.jetty.Response|File: Response.java|Method: getWriter|Line: 616 - org/mortbay/jetty/Response.java:616:-1 2015

java.lang.IllegalStateException

java.lang.IllegalStateExceptionorg.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:423)经过分析.查看jdk文档终于找到解决的办法,在response.sendRedirect()方法后加return语句即可,如下:response.sendRedirect(login.jsp);return null;原因是:在程序中两次调用了response.sendRe