2017-04-03 27 views
0

Springブートのドキュメントによれば、staticフォルダ内のリソースは、追加の構成や要求マッピングなしでSpringブートによって自動的に提供されます。私はここでhttp://localhost:8080/js/filter.jsSpringブートで静的リソースにアクセスできない


に行くことによってjavascriptのファイルにアクセスしようとしています

春のドキュメントのその部分のそのセクションのスクリーンショットです。ここで

spring documentation screenshot


私の現在のresourcesのディレクトリ構造のスクリーンショットです。ここで

directory structure


私は、最新の春のブートリリースを使用していることを示すために私のpom.xmlです。

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.example</groupId> 
    <artifactId>velocity-demo</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>velocity-demo</name> 
    <description>Demo project for Spring Boot</description> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.2.RELEASE</version> 
     <relativePath/> <!-- lookup parent from repository --> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
     <java.version>1.8</java.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 

     <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> 
     <dependency> 
      <groupId>org.apache.velocity</groupId> 
      <artifactId>velocity</artifactId> 
      <version>1.7</version> 
     </dependency> 
     <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> 
     <dependency> 
      <groupId>com.google.code.gson</groupId> 
      <artifactId>gson</artifactId> 
      <version>2.8.0</version> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 

</project> 

は、ここで私は@PostMapping("/foo")@PostMappingを変え、私のコントローラでは、私のApplicationクラス

package com.example 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 

@SpringBootApplication 
public class VelocityDemoApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(VelocityDemoApplication.class, args); 
    } 

} 
+0

あなたが表示するものは問題ありません。この問題はおそらくあなたのSpring設定の何かによって引き起こされます。あなたはそのすべてを見せてもらえますか? – davidxxx

+0

これ以上の設定はありません。 Applicationクラスを投稿に追加しますが、バニラクラスです。 – qbolt

+0

確かに。それはむしろ単純です。しかし、それは**すべての**ですか?私はちょうどテストして、それは動作します。 – davidxxx

答えて

0

で、今私は私のすべてのリソースを取得することができます。それは基本的にすべての私の要求をブロックしていた。

このように設定されているコントローラが他のすべてのリクエストをブロックしているとは思わないので、もちろん削除されない限り、この質問を残しておきます。誰かがこの問題を1日持つ可能性があります。

@RestController 
public class MainController { 

    TemplateService templateService; 

    public MainController(TemplateService templateService) { 
     this.templateService = templateService; 
    } 

    @GetMapping("/") 
    public String getIndex() { 
     return templateService.getTemplate("index.vm"); 
    } 

    @PostMapping("/updateFilter") // was @PostMapping 
    public String updateFilter() { 
     System.out.println("updating filter"); 
     return "success"; 
    } 
} 
関連する問題