2014-10-17 54 views
1

我正在使用Spring Boot,thymeleaf和webjars創建一個非常基本的小型web應用程序。webjars - > HTTP 406

我想要什麼: 包括jQuery和引導使用webjars

我做了什麼: 我包括依賴到我的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> 

問題:儘管百里香葉罐在我的/ lib目錄中,並且對我來說一切看起來都正確,但它d沒有工作。在瀏覽器中顯示的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 

回答

2

如何配置WebMVC?

Here你可以找到一個介紹如何使用webjars與Spring WebMVC。

+0

謝謝你,你的提示解決了我的問題。我只是使用註釋EnableAutoConfiguration,所以我添加了註釋EnableWebMcv並且它可以工作。引言是第一個搜索結果之一,所以我已經知道了(如果沒有的話,會是一種恥辱)。 – dexBerlin 2014-10-17 08:45:40

+0

如果您啓用'EnableWebMvc',則關閉Spring Boot中的所有MVC默認值。很好,如果那是你想要的,但我不會那樣做。它適用於'/ webjars/jquery/2.1.1/jquery.min.js'開箱即用,所以406可能是由你做的其他事情引起的。 – 2014-10-17 10:36:29