2016-07-16 227 views
0

我在Spring Boot應用程序中添加了ThymeleafConfig,因此我可以將模板模式配置爲HTML5。在添加之前,Spring Boot應用程序可以找到home.html模板。現在加入它後,我得到一個:在Spring Boot中對ThymeleafConfig感到困惑

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "home", template might not exist or might not be accessible by any of the configured Template Resolvers 

我的目錄結構是一個標準的資源/模板/ home.html的

這裏是我的ThmyeleafConfig:

import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.context.support.ResourceBundleMessageSource; 
import org.thymeleaf.templateresolver.ServletContextTemplateResolver; 

@Configuration 
public class ThymeleafConfig { 

    @Bean 
    public ServletContextTemplateResolver defaultTemplateResolver() { 
     ServletContextTemplateResolver resolver = new ServletContextTemplateResolver(); 
     resolver.setPrefix("/templates/"); 
     resolver.setSuffix(".html"); 
     resolver.setTemplateMode("LEGACYHTML5"); 
     resolver.setCacheable(false); 
     return resolver; 
    } 

    @Bean 
    public ResourceBundleMessageSource messageSource() { 
     ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); 
     messageSource.setBasename("messages"); 
     messageSource.setDefaultEncoding("UTF-8"); 

     return messageSource; 
    } 
} 

我敢肯定我我已經遵循了這些例子,但顯然有一些我錯過了。任何建議如何我可以解決這個問題,以便它找到正確的模板?

+0

爲什麼你需要添加這個?百靈葉已經由Spring Boot爲您配置了? –

+0

這是,但問題是,像這樣的angularjs指令無法解析。所以我看到的建議是將模式設置爲LEGACYHTML5或HTML5而不是默認設置。我會嘗試安迪在下面顯示的內容,但我願意接受其他解決方案,並且有興趣知道我在這裏做了什麼具體的錯誤。 –

回答

2

有沒有必要申報自己的豆。你可以使用application.properties配置模式:

spring.thymeleaf.mode=LEGACYHTML5