2017-02-20 3 views
1

なぜ私はSpring Bootが404 Not Foundを別々に扱っているのだろうと思っています。エンティティのためにSpringブート処理が "404 Not Found"と異なるのはなぜですか?

なしパスの例に

を既存私はカールとなし、既存のパス上の要求を行います。 enter image description here

そして今、私が要求:ブラウザで

$ curl -v -H "Authorization: Basic YWRtaW46YWRtaW4xMjM=" http://localhost:8080/no/endpoint | python -m json.tool 
* Adding handle: conn: 0x69aa30 
* Adding handle: send: 0 
* Adding handle: recv: 0 
* Curl_addHandleToPipeline: length: 1 
* - Conn 0 (0x69aa30) send_pipe: 1, recv_pipe: 0 
    % Total % Received % Xferd Average Speed Time Time  Time Current 
           Dload Upload Total Spent Left Speed 
    0  0 0  0 0  0  0  0 --:--:-- --:--:-- --:--:--  0* About to connect() to localhost port 8080 (#0) 
* Trying 127.0.0.1... 
* Connected to localhost (127.0.0.1) port 8080 (#0) 
> GET /no/endpoint HTTP/1.1 
> User-Agent: curl/7.33.0 
> Host: localhost:8080 
> Accept: */* 
> Authorization: Basic YWRtaW46YWRtaW4xMjM= 
> 
< HTTP/1.1 404 
< Set-Cookie: JSESSIONID=62B5B02F18842F3BD46BCE57F2EAB017;path=/;HttpOnly 
< X-Application-Context: Rechnungsservice Gateway:dev 
< X-Content-Type-Options: nosniff 
< X-XSS-Protection: 1; mode=block 
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate 
< Pragma: no-cache 
< Expires: 0 
< Content-Type: application/json;charset=UTF-8 
< Transfer-Encoding: chunked 
< Date: Mon, 20 Feb 2017 11:59:19 GMT 
< 
{ [data not shown] 
100 115 0 115 0  0 569  0 --:--:-- --:--:-- --:--:-- 614 
* Connection #0 to host localhost left intact 
{ 
    "error": "Not Found", 
    "message": "No message available", 
    "path": "/no/endpoint", 
    "status": 404, 
    "timestamp": 1487591959599 
} 

同じ操作を存在しないエンティティのエンドポイント:

ブラウザで
$ curl -v -H "Authorization: Basic YWRtaW46YWRtaW4xMjM=" http://localhost:8080/api/v1/settings/123 | python -m json.tool                              

* Adding handle: conn: 0x62aa40                      
* Adding handle: send: 0                        
* Adding handle: recv: 0                        
* Curl_addHandleToPipeline: length: 1                     
* - Conn 0 (0x62aa40) send_pipe: 1, recv_pipe: 0                  
    % Total % Received % Xferd Average Speed Time Time  Time Current          
           Dload Upload Total Spent Left Speed           
    0  0 0  0 0  0  0  0 --:--:-- --:--:-- --:--:--  0* About to connect() to localhost port 8 
080 (#0)                            
* Trying 127.0.0.1...                        
* Connected to localhost (127.0.0.1) port 8080 (#0)                 
> GET /api/v1/settings/123 HTTP/1.1                     
> User-Agent: curl/7.33.0                        
> Host: localhost:8080                         
> Accept: */*                           
> Authorization: Basic YWRtaW46YWRtaW4xMjM=                   
>                              
< HTTP/1.1 404                           
< Set-Cookie: JSESSIONID=BCD5ADDA48EB03C235E6573A36860F7D;path=/;HttpOnly            
< X-Application-Context: Rechnungsservice Gateway:dev                 
< X-Content-Type-Options: nosniff                      
< X-XSS-Protection: 1; mode=block                      
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate              
< Pragma: no-cache                          
< Expires: 0                           
< Content-Length: 0                         
< Date: Mon, 20 Feb 2017 12:05:29 GMT                     
<                              
    0  0 0  0 0  0  0  0 --:--:-- --:--:-- --:--:--  0           
* Connection #0 to host localhost left intact                   
No JSON object could be decoded  

同じ操作: enter image description here

だから私の質問です:なぜ春ブーツだけでは見られないエンティティの場合には、単純な404のステータスを送信していますか?素敵なメッセージを見たいと思います:Entityが見つからないか、またはtext/htmlのエラーページまたはjsonリクエストの場合のjsonエラーオブジェクトにこのようなものがあります...パスの例では、箱...

私は春のブート1.4.3.RELEASEを使用しています。

UPDATE:私は春データ休息を使用していますと言うのを忘れて 申し訳ありません。私の意見で

class RepositoryEntityController ... { 

public ResponseEntity<Resource<?>> getItemResource(...) { 

Object domainObj = getItemResource(resourceInformation, id); 

    if (domainObj == null) { 
     return new ResponseEntity<Resource<?>>(HttpStatus.NOT_FOUND); 
    } 

} 

良好な応答につながる、「NotFoundException」をスローする必要が存在しない単一のエンティティへの要求: そして、ここでは、私は、このコードスニペットを見つけuntiデバッグ。

答えて

2

最初のリクエストがSpringアプリケーションに届かないため、WARはその場所にデプロイされないため、Webサーバー(Tomcatなど)から汎用404メッセージが取得されます。

関連する問題