2017-05-12 12 views
1

ここで完全に困っています。私のブートアプリケーションは静的リソースを提供していません。 CSSが適用されていない、画像がロードされていない。まだセキュリティはないので、それは問題だとは思わない。私はSpringboot - リソースはスタイルシートとして解釈されますが、MIMEタイプtext/htmlで転送されます

Resource interpreted as Stylesheet but transferred with MIME type text/html 

すべてが200

Shows everything loading

である。しかし、あなたが応答を見れば...それは

enter image description here

をブートストラップないのgetコンソール出力を確認する

私は信じている私は、コード正しいデフォルトのファイル構造

ここ

enter image description here

をい使用しています:

のpom.xml

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-actuator</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-thymeleaf</artifactId> 
    </dependency> 
    <!-- WEB JARS --> 
    <dependency> 
     <groupId>org.webjars</groupId> 
     <artifactId>bootstrap</artifactId> 
     <version>3.3.7-1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.webjars</groupId> 
     <artifactId>jquery</artifactId> 
     <version>3.2.0</version> 
    </dependency> 
    <!-- JDBC --> 
    <dependency> 
     <groupId>net.sourceforge.jtds</groupId> 
     <artifactId>jtds</artifactId> 
     <version>1.3.1</version> 
    </dependency> 
    <!-- LOGGING --> 
    <dependency> 
     <groupId>net.logstash.logback</groupId> 
     <artifactId>logstash-logback-encoder</artifactId> 
     <version>4.7</version> 
    </dependency> 
    <!-- SCOPED JARS--> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-devtools</artifactId> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <configuration> 
       <executable>true</executable> 
      </configuration> 
     </plugin> 
    </plugins> 
     <finalName>${project.artifactId}</finalName> 
</build> 

テンプレート/ index.htmlを

<!DOCTYPE HTML> 
<html xmlns:th="http://www.thymeleaf.org"> 
<head lang="en" th:include="fragments/headerinc :: head"> 
    <title>Demo App</title> 
    <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"/> 
</head> 
<body> 
<div class="container-fluid"> 
    <nav class="navbar navbar-inverse navbar-static-top"> 
     <div class="container-fluid"> 
      <div class="navbar-header"> 
       <button type="button" class="navbar-toggle collapsed" 
         data-toggle="collapse"> 
        <span class="sr-only">Toggle navigation</span> <span 
         class="icon-bar"></span> <span class="icon-bar"></span> <span 
         class="icon-bar"></span> 
       </button> 
       <a class="navbar-brand" href="#"> 
        <img style="width: 75px;" th:src="@{~/images/logo.png}"/>My APP</a> 
      </div> 
      <div id="navbar5" class="navbar-collapse collapse"> 
       <ul class="nav navbar-nav navbar-right"> 
        <li class="active"><a href="#">Home</a></li> 
        <li><a href="#">Journal</a></li> 
        <li><a href="#">Etc</a></li> 
       </ul> 
      </div> 
     </div> 
    </nav> 
</div> 

テンプレート/フラグメント/ headerinc.html

<!DOCTYPE HTML> 
<html xmlns:th="http://www.thymeleaf.org"> 
<head lang="en" th:fragment="head"> 
    <meta http-equiv="content-type" content="text/html" charset="UTF-8"/> 
    <link href="http://cdn.jsdelivr.net/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" 
      th:href="@{/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css}" 
      rel="stylesheet" media="screen" /> 
    <link href="../css/styles.css" th:href="@{/css/styles.css}" 
      type="text/css" rel="stylesheet" media="all"/> 
</head> 
<body> 
</body> 
</html> 

任意の提案をいただければ幸いです!

+0

'/ webjars/**'パターンに対して[リソースハンドラを追加しました](https://spring.io/blog/2014/01/03/utilizing-webjars-in-spring-boot)しましたか? – manish

+0

これはすべての静的コンテンツを誤って提供しています。たとえば、localhost/css/styles.cssは404を与えず、むしろindex.htmlをレンダリングします。 – datGnomeLife

+0

この問題をどのように解決しましたか? – imdzeeshan

答えて

1

Mavenの依存性を用いてWebjarsを用いる場合には、コントローラー要求方法ががURIは以下のように、単に/場合でもことを指定すべきです。

@RequestMapping(value = "/") 
public String index() { 
    return "welcome"; 
} 

しかし、あなたはリソース/静的フォルダ内のすべてのCSSJSを入れている場合は、は自動的に対応する応答を送信します。

関連する問題