2016-09-01 14 views
3

春のアプリケーション(とそのことについては、春のブート)でしばらくの間苦労した後、私はついにそれを働かそうとしているようだ。spring boot - テンプレートの場所を正しく定義する方法は?

私はすでに依存関係解決とmavenビルドを移行しました。アプリケーションが起動(と非常に迅速に!)が、私は

localhost:8080

にアクセスしようとしたとき、私は、アプリケーションのランディングページにアクセスするたびに、私は以下のブラウザメッセージが表示されます:

HTTP Status 500 - Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "home/homeNotSignedIn", template might not exist or might not be accessible by any of the configured Template Resolvers 

src/main/resourcesフォルダがあります

src/main/resources 
    static // CSS, IMG and JS 
    templates // html 
    application.properties 
    log4j.properties 

は今、私はコンセプトを混合することができる理解が、私のApplicationConfiguration.javaに私はトンを持っています彼:application.properties

@Configuration 
@EnableWebMvc 
@ComponentScan(basePackages = "b.c.g.c") 
public class ApplicationConfiguration extends WebMvcConfigurerAdapter { 

    @Bean 
    @Description("Thymeleaf template resolver serving HTML 5") 
    public ServletContextTemplateResolver templateResolver() { 
     ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(); 
     templateResolver.setCacheable(false); 
     templateResolver.setTemplateMode("HTML5"); 
     templateResolver.setCharacterEncoding("UTF-8"); 
     templateResolver.setPrefix("classpath:/templates/"); 
     templateResolver.setSuffix(".html"); 

     return templateResolver; 
    } 

    @Bean 
    @Description("Thymeleaf template engine with Spring integration") 
    public SpringTemplateEngine templateEngine() { 
     SpringTemplateEngine templateEngine = new SpringTemplateEngine(); 
     templateEngine.addDialect(new SpringSecurityDialect()); 
     templateEngine.addDialect(new LayoutDialect(new GroupingStrategy())); 
     templateEngine.setTemplateResolver(templateResolver()); 

     return templateEngine; 
    } 

    @Bean 
    @Description("Thymeleaf view resolver") 
    public ViewResolver viewResolver() { 

     ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); 
     viewResolver.setTemplateEngine(templateEngine()); 
     viewResolver.setCharacterEncoding("UTF-8"); 
     viewResolver.setCache(false); 
     viewResolver.setOrder(1); 

     return viewResolver; 
    } 

    // other beans 
} 

そして、私はこれを持っている:

spring.thymeleaf.check-template-location=true 
spring.thymeleaf.prefix=classpath:templates/ 
spring.thymeleaf.suffix=.html 
spring.thymeleaf.mode=HTML5 
spring.thymeleaf.encoding=UTF-8 
spring.thymeleaf.content-type=text/html 
spring.thymeleaf.cache=false 

私はこれらの抜粋は同じ事、私は右、人は行くことができます賭けを教えて見ますが?

ので、二つの質問、実際には、

1)春+ Thymeleafはどこのテンプレートを見つけるために理解してくださいするには?

2)アプリケーションをlocalhost:8080/appNameの代わりにlocalhost:8080/の代わりにする方法を教えてください。

+1

これを構成する理由はありますか?そのテンプレートレゾルバ全体がデフォルトの自動設定です。 – chrylis

答えて

2

私が最初にあなたの2番目の質問

  1. にお答えします
    推奨アプローチあなたはSRC /メイン/リソースにapplication.propertiesまたはapplication.yml(YAMLが優れている)ファイルを定義しています。 Spring-Bootにはdefault propertiesファイルがあり、コンテキストパス(Webプロパティを探す)、ポートのすべてを設定できます。

    server.context-path=/<appname> 
    
  2. あなたはプロパティファイルでthymeleaf構成を参照することができ、あなたの2番目の質問スプリングブートに答えるために。

+0

ありがとう、バディ!コンテキストパスが機能します!しかし、私はまだランディングページには到達できません... – gtludwig

+1

JARファイルまたはWARファイルとしてパックしていますか? –

+0

Preveen、私は戦争として梱包しています。 – gtludwig

関連する問題