Spring Boot返回" 200 OK" (空响应)资源目录,而不是文件

时间:2016-11-28 21:19:23

标签: java spring http spring-boot staticresource

我正在构建一个基本的Spring Boot应用程序,使用内置的资源处理程序。

registry.addResourceHandler("/**")
        .addResourceLocations("classpath:/public/")
        .setCachePeriod(60 * 60 * 24 * 365)
        .resourceChain(true)
        .addResolver(versionResourceResolver);

文件结构如下:

src
  main
    java
      ..
    resources
      public
        js
          app.js

localhost:8080/js/app.js发出请求按预期工作,返回具有正确MIME类型的文件内容。

但是,向容器目录发出请求也会返回200 OK和空响应!

$ curl -v http://localhost:8080/js/
*   Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /js/ HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.49.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 28 Nov 2016 21:13:26 GMT
< X-Application-Context: application
< Last-Modified: Mon, 28 Nov 2016 21:06:28 GMT
< Cache-Control: max-age=31536000
< Accept-Ranges: bytes
< Content-Type: application/octet-stream
< Content-Length: 0
<
* Connection #0 to host localhost left intact

如何才能让它返回404 Not Found?这不是一个大问题,但绝对不是我所期望的。

0 个答案:

没有答案