Spring cloud encounters problems using feign

Source: Internet
Author: User

Tag: timeout color int enters personal res ping cond. exe

Spring Cloud uses the feign project is not written here, this article mainly explains the problems encountered in the use process and solutions

1: Example

1 @RequestMapping (value = "/generate/password", method = requestmethod.post)2  Keyresponse Generatepassword (@RequestBody String passwordseed); 3 can only be used here @RequestMapping (value = "/generate/password", method = requestmethod.post) annotations cannot be used @PostMapping otherwise Project launch will be reported 4 caused By:java.lang.IllegalStateException:Method Generatepassword not annotated with HTTP Method Type (ex. GET, POST) exception

2: First time Access timeout issue

Cause: Hystrix The default time-out is 1 seconds, and if the time is not yet responding, it will enter the fallback code.
The first request tends to be slow (because of the lazy loading mechanism of spring, to instantiate some classes), the response time may be more than 1 seconds.
Workaround:

<1: The timeout for configuring Hystrix is changed to 5 seconds

hystrix.command.default.execution.isolation.thread.timeoutinmilliseconds:5000

<2: Disable Hystrix time-out

Hystrix.command.default.execution.timeout.enabled:false

<3: Disabling the Hystrix function of feign

Feign.hystrix.enabled:false

Note: Personal recommendation first or second method

3:feignclient interface, if you use to @pathvariable, you must specify its value

Spring Cloud feign using Apache HttpClient

Issue: 1 Unspecified content-type is the case where the following exception occurs? You're wondering here?

1 caused By:java.lang.IllegalArgumentException:MIME type may not contain reserved characters

Interested in here friends can go to study the source

1Apachehttpclient.class 2   PrivateContentType getContentType (Request request) {3ContentType ContentType =Contenttype.default_text;4      for(Map.entry<string, collection<string>>entry:request.headers (). EntrySet ())5     //This will determine if you do not specify the Content-type attribute to use the above default text/plain; Charset=iso-8859-16     //The problem is the default contentType: Format Text/plain; charset=iso-8859-17     //go to Contenttype.create (Entry.getvalue (). iterator (). Next (), Request.charset ());8     if(Entry.getkey (). Equalsignorecase ("Content-type")) {9Collection values =Entry.getvalue ();Ten       if(Values! =NULL&&!Values.isempty ()) { OneContentType =contenttype.create (Entry.getvalue (). iterator (). Next (), Request.charset ()); A          Break; -       } -     } the     returnContentType; -}
1ContentType.class2     Public StaticContentType Create (FinalString MimeType,FinalCharset Charset) {3         FinalString Normalizedmimetype = Args.notblank (MimeType, "MIME type"). toLowerCase (locale.root);4     //The problem is in this check in the valid F method5Args.check (Valid (Normalizedmimetype), "MIME type may not contain reserved characters");6         return NewContentType (Normalizedmimetype, CharSet);7     }8    Private Static BooleanValidFinalString s) {9          for(inti = 0; I < s.length (); i++) {Ten             Final CharCH =S.charat (i); One         //There's a semicolon in the top text/plain;charset=utf-8, causing the test not to pass. A             if(ch = = ' "' | | ch = = ', ' | | ch = = '; ') { -                 return false; -             } the         } -         return true; -}

Workaround:

@RequestMapping (value = "/generate/password", method = requestmethod.post, consumes = Mediatype.application_json_value )

Specified in the note: Content-type is the attribute value of the specified consumes: here the value of the consumes attribute is not specifically explained here, interested can be studied under

Temporarily encounter the above problems, follow-up in-depth study if there is a problem will be updated in time, I hope you can help thank you

Spring cloud encounters problems using feign

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.