Spring Boot不提供静态javascript文件

时间:2016-09-13 21:23:43

标签: javascript java spring spring-mvc spring-boot

我有一个非常奇怪的Spring Boot应用程序行为(1.4.0.RELEASE)

我的静态内容位于/src/main/resources/static/*下,其中一个页面需要css和js文件,但是尽管css文件服务没有问题,但我得到的是js文件的404:

对于CSS文件,我在日志中看到

SimpleUrlHandlerMapping  : No handler mapping found for [/admin_files/custom_admin.css]
RequestMappingHandlerMapping : Looking up handler method for path /admin_files/custom_admin.css
RequestMappingHandlerMapping : Did not find handler method for [/admin_files/custom_admin.css]
SimpleUrlHandlerMapping: Matching patterns for request [/admin_files/custom_admin.css] are [/**]
SimpleUrlHandlerMapping  : Mapping [/admin_files/custom_admin.css] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/], (...)

所以它看起来完全没问题。但是对于JS文件,它看起来不同:

SimpleUrlHandlerMapping  : No handler mapping found for [/admin_files/vendor/jquery/dist/jquery.min.js]
RequestMappingHandlerMapping : Did not find handler method for [/admin_files/vendor/jquery/dist/jquery.min.js]
SimpleUrlHandlerMapping  : Matching patterns for request [/admin_files/vendor/jquery/dist/jquery.min.js] are [/**]
SimpleUrlHandlerMapping  : Mapping [/admin_files/vendor/jquery/dist/jquery.min.js] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/] (...)
//
// and now something strange starts to happen BELOW
//
HttpEntityMethodProcessor  : Written [{timestamp=Tue Sep 13 23:17:12 CEST 2016, status=404, error=Not Found, message=No message available, path=/admin_files/vendor/jquery/dist/jquery.min.js}] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@29139aae]

我真的被卡住了,因为它看起来像一个非常小的故障或者我在某处遗失的非常小的东西。

我的应用程序如下所示:

@SpringBootApplication
@EnableAsync
@EnableTransactionManagement(proxyTargetClass = true)
@EnableEncryptableProperties
public class Application extends WicketBootSecuredWebApplication { }

没有任何自定义配置bean等。

tree执行了

/src/main/resources

.
├── application-dev.yml
├── application-prod.yml
├── application-staging.yml
├── application.yml
├── banner.txt
└── static
    └── admin_files
        ├── custom_admin.css
        └── vendor
            ├── jquery
            │   ├── jquery.js
            │   └── jquery.min.js
            └── metisMenu
                ├── metisMenu.css
                ├── metisMenu.js
                ├── metisMenu.min.css
                └── metisMenu.min.js

任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:1)

请注意,您要求/admin_files/vendor/jquery/dist/jquery.min.js但在资源树中 dist 目录不存在。