2017-02-19 14 views
1

私が初めて春ブーツで表示Freemarkerのビューを取得し、現在、ブラウザに次のエラーを取得しようとしています:春ブーツ

ホワイトレーベルのエラーページ

このアプリケーションに/ errorの明示的なマッピングがないため、 がフォールバックとして表示されます。

Sun Feb 19 17:59:07 GMT 2017予期しないエラーが発生しました(タイプ= Not が見つかりました、ステータス= 404)。メッセージはありません

私はSpring Boot 1.5を使用しています。

マイファイル構造:

enter image description here

LoginController

package com.crm.controller; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 

import com.crm.service.LoginService; 

@Controller 
public class LoginController { 

    @Autowired 
    private LoginService loginService; 

    @RequestMapping("/login") 
    public String authenticate() { 
     return "loginPage"; 
    } 
} 

application.properties

spring.freemarker.template-loader-path:/
spring.freemarker.suffix: .ftl 

サーバー

package com.crm; 

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

@SpringBootApplication 
public class Server{ 

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

なぜSpringがloginPage.ftlビューを解決できないのですか?なぜ私はそれをWebブラウザで見ることができないのですか?

答えて

2

春ブーツ1.5.1を使用すると、彼らはすでに、自動設定のおかげで定義されている、あなたのapplication.propertiesファイルにこれらのプロパティを追加する必要はありません。

これら2つのプロパティを削除し、それがあなたのpom.xmlに以下の依存関係で動作します:

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

マニュアルは、ここで見つけることができます:http://docs.spring.io/spring-boot/docs/1.5.1.RELEASE/reference/htmlsingle/#boot-features-spring-mvc-template-engines

+0

ログインページやThymeleaf/FreeMarkerのようにスプリングセキュリティを使用している場合は、構成に@EnableWebSecurityを追加してリソースが正しく解決されるようにしてください。 – rdlopes

+1

上記のリンクで説明したとおりです。テンプレートエンジンは、 'src/main/java/resources/templates'ではなく' src/main/resources/templates'を見ます。 – crm

2

freemarkerテンプレートのディレクトリ設定がapplication.propertiesで間違っています。それは次のようになります。

spring.freemarker.template-loader-path=classpath:/templates/ 
+0

私はあなたが 'application.properties'ファイルを意味すると思います'application.xml'ファイルではありません。 –

+0

その変更はそれを修正していません。 – crm

+0

@crmビューが呼び出されているかどうか確認してください。 –