【问题标题】:Spring Boot not serving static javascript fileSpring Boot 不提供静态 JavaScript 文件
【发布时间】:2017-01-21 14:18:58
【问题描述】:

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

我的静态内容位于/src/main/resources/static/* 下,其中一个页面需要 css 和 js 文件,但尽管 css 文件可以毫无问题地提供,但我得到 404 的 js 文件:

对于我在日志中看到的 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

任何帮助表示赞赏!

【问题讨论】:

  • 您是配置了mvc 选项还是让它自动配置?
  • @nurgasemetey 我的yaml文件中没有mvc相关配置。
  • 请添加项目/资源树
  • @reos 完成,tree 输出已添加。但是将静态文件放置在适当的目录中会有些麻烦,css和js文件都无法正确提供。

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    • 2019-03-30
    • 2021-09-11
    • 1970-01-01
    • 2019-09-20
    • 2021-06-19
    • 2018-11-25
    相关资源
    最近更新 更多