Java 为什么Spring Boot处理的是“a”;“404未找到”;不同的实体?
我想知道为什么Spring Boot处理404时没有发现不同 无现有路径示例 我使用curl在不存在的路径上发出请求:Java 为什么Spring Boot处理的是“a”;“404未找到”;不同的实体?,java,spring,spring-mvc,spring-boot,spring-data-rest,Java,Spring,Spring Mvc,Spring Boot,Spring Data Rest,我想知道为什么Spring Boot处理404时没有发现不同 无现有路径示例 我使用curl在不存在的路径上发出请求: $ 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: rec
$ 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“授权:基本YWRtaW46YWRtaW4xMjM=”http://localhost:8080/no/endpoint |python-mjson.tool
*正在添加句柄:conn:0x69aa30
*正在添加句柄:发送:0
*正在添加句柄:recv:0
*卷曲度加把手尺寸线:长度:1
*-Conn 0(0x69aa30)发送管道:1,接收管道:0
%总接收百分比%x平均速度时间电流
数据加载上载总左速度
0 0 0 0 0 0--:-:---:---:---:---0*即将()连接到本地主机端口8080(#0)
*正在尝试127.0.0.1。。。
*已连接到本地主机(127.0.0.1)端口8080(#0)
>GET/no/endpoint HTTP/1.1
>用户代理:curl/7.33.0
>主机:本地主机:8080
>接受:*/*
>授权:基本YWRtaW46YWRtaW4xMjM=
>
与浏览器相同的操作:
现在我为一个不存在的实体请求一个端点:
$ 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
$curl-v-H“授权:基本YWRtaW46YWRtaW4xMjM=”http://localhost:8080/api/v1/settings/123 |python-mjson.tool
*正在添加句柄:conn:0x62aa40
*正在添加句柄:发送:0
*正在添加句柄:recv:0
*卷曲度加把手尺寸线:长度:1
*-Conn 0(0x62aa40)发送管道:1,接收管道:0
%总接收百分比%x平均速度时间电流
数据加载上载总左速度
0 0 0 0 0 0--:-:-:---:---:---:---0*即将连接()到本地主机端口8
080 (#0)
*正在尝试127.0.0.1。。。
*已连接到本地主机(127.0.0.1)端口8080(#0)
>GET/api/v1/settings/123 HTTP/1.1
>用户代理:curl/7.33.0
>主机:本地主机:8080
>接受:**
>授权:基本YWRtaW46YWRtaW4xMjM=
>
在浏览器中执行相同的操作:
所以我的问题是:为什么Spring Boot只在找不到实体的情况下发送一个简单的404状态?我想在我的文本错误页面上看到一条很好的消息:找不到实体或类似的东西/
class RepositoryEntityController ... {
public ResponseEntity<Resource<?>> getItemResource(...) {
Object domainObj = getItemResource(resourceInformation, id);
if (domainObj == null) {
return new ResponseEntity<Resource<?>>(HttpStatus.NOT_FOUND);
}
}