2015-02-09 23 views
4

當我傳遞的電子郵件地址作爲路徑變量它拋出以下錯誤網址路徑中的可變彈簧RESTful服務

Console --> 2015-02-09 16:30:06,634 WARN - GET request for "http://localhost:8181/abc/users/[email protected]" resulted in 406 (Not Acceptable); invoking error handler 
Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 406 Not Acceptable 
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91) 
    at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:607) 
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:565) 
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:521) 
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:439) 
    at RestClient.main(RestClient.java:35) 

我已經試過很多情況下,我終於找到了像最後一個域的問題.com.org這是域名國際化。因此,如果我通過「[email protected]」,而不是「[email protected]」,它將工作得很好。

我的代碼是

@RequestMapping(value = "users/{emailId:.*}", method = RequestMethod.GET) 
    public Object searchUser(@PathVariable("emailId") String emailId){ 
     logger.info("Inside search user --> emailId " + emailId); 
     return userService.findUserByuserId(emailId); 
} 
+0

你好,我也有同樣的問題。你已經解決了它..?如果是,請幫忙。改變其對於.dom的正常工作。 – 2015-05-28 07:51:49

+0

嗨Saurabh,我找到了一個工作,看看我的答案,它應該幫助你。 – commit 2015-05-29 07:33:17

回答

4

我沒有找到答案。我認爲這是一個http規則,我們最終可以在參數中找不到域,並且可以提出請求。

因此,解決這個問題只是在網址的末尾傳遞斜線,然後就可以了。

像修改「http://localhost:8181/abc/users/[email protected]/」與「http://localhost:8181/abc/users/[email protected]」。並且,由於採用了春季休息架構,它將自動省略最後一個斜槓,並且您將獲得「[email protected]」作爲參數值。

讓我知道如果你們找到別的東西。

+0

嘿,是的,它也適用於我。很好的幫助。謝謝 – 2015-06-02 05:49:58