【问题标题】:webjars -> HTTP 406webjars -> HTTP 406
【发布时间】:2014-12-12 18:04:59
【问题描述】:

我正在使用 Spring Boot、thymeleaf 和 webjars 创建一个非常基本的小型 Web 应用程序。

我想要的: 使用 webjars 包含 jquery 和 bootstrap

我做了什么: 我将依赖项包含在我的 pom.xml 中

<dependency>
  <groupId>org.webjars</groupId>
  <artifactId>bootstrap</artifactId>
  <version>3.2.0</version>
</dependency>
<dependency>
  <groupId>org.webjars</groupId>
  <artifactId>jquery</artifactId>
  <version>2.1.1</version>
</dependency>

我将 jquery 添加到我的模板 index.html:

<script src="/webjars/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>

问题:虽然 thymeleaf 罐子在我的 /lib 目录中,而且对我来说一切看起来都正确,但它不起作用。浏览器中显示的 HTML 文件显示了脚本行,但尝试直接获取 jquery 库(在 Chrome 浏览器中单击源)最终会出现 HTTP 406 错误,而路径显示为http://localhost:8080/webjars/jquery/2.1.1/jquery.min.js

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Fri Oct 17 09:34:32 CEST 2014
There was an unexpected error (type=Not Acceptable, status=406).
Could not find acceptable representation

【问题讨论】:

    标签: java spring-boot thymeleaf webjars


    【解决方案1】:

    如何配置 WebMVC?

    Here你可以找到一个介绍如何在 Spring WebMVC 中使用 webjars。

    【讨论】:

    • 谢谢,您的提示解决了我的问题。我只是使用了批注 EnableAutoConfiguration,所以我添加了批注 EnableWebMcv 并且它可以工作。简介是最早的搜索结果之一,所以我已经知道了(如果不知道,那就太可惜了)。
    • 如果你 EnableWebMvc 你从 Spring Boot 中关闭所有 MVC 默认值。好吧,如果那是你想要的,但我不会那样做。它对我来说是开箱即用的 /webjars/jquery/2.1.1/jquery.min.js 所以 406 可能是由你所做的其他事情引起的。
    猜你喜欢
    • 2019-01-21
    • 2023-03-17
    • 1970-01-01
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多