2016-08-22 5 views
0

스프링 부트 애플리케이션을 올바르게 설정하는 데 문제가 있습니다. 나는 다음과 같은 한 능숙 측면에서봄 부팅시 Thymleaf 템플릿이 올바르게 사용되지 않습니다.

@Configuration 
public class WebConfig extends WebMvcConfigurerAdapter { 

@Override 
public void addResourceHandlers(ResourceHandlerRegistry registry) { 
    registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); 
} 

@Override 
public void addViewControllers(ViewControllerRegistry registry) { 
    registry.addViewController("/login").setViewName("security/login"); 
} 

@Bean 
public ViewResolver viewResolver() { 
    ThymeleafViewResolver resolver = new ThymeleafViewResolver(); 
    resolver.setTemplateEngine(templateEngine()); 
    resolver.setCharacterEncoding("UTF-8"); 
    return resolver; 
} 

@Bean 
public SpringTemplateEngine templateEngine() { 
    SpringTemplateEngine templateEngine = new SpringTemplateEngine(); 

    Set<IDialect> dialects = new HashSet<IDialect>(); 
    dialects.add(springSecurityDialect()); 

    templateEngine.setAdditionalDialects(dialects); 
    templateEngine.setTemplateResolver(templateResolver()); 
    return templateEngine; 
} 

@Bean 
public SpringSecurityDialect springSecurityDialect() { 
    SpringSecurityDialect dialect = new SpringSecurityDialect(); 
    return dialect; 
} 

@Bean 
public TemplateResolver templateResolver() { 
    SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); 
    resolver.setPrefix("templates/"); 
    //resolver.setSuffix(".html"); 
    return resolver; 
} 
} 

:

/src 
--/main 
----/resources 
------/template 
--------/home 
----------/home.html 
--------/security 
----------/login.html 

I

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.3.3.RELEASE</version> 
    <relativePath /> 
</parent> 

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

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-hateoas</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-jdbc</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-security</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-ldap</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-actuator</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-thymeleaf</artifactId> 
    </dependency> 

이 웹 응용 프로그램 구성 : 기본적으로

나는이 pom.xml 파일을 이 클래스도 있습니다 :

10 내가 수정도 다음과 같은 오류를 이해 할 수없는 것은, 아무리 :

2016-08-19 11:40:58.707 ERROR 6874 --- [nio-8080-exec-1]   org.thymeleaf.TemplateEngine    : [THYMELEAF][http-nio-8080-exec-1]  Exception processing template "home/home": Error resolving template "home/home", template might not exist or might not be accessible by any of the configured Template Resolvers 
2016-08-19 11:40:58.723 ERROR 6874 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet]  : Servlet.service() for servlet [dispatcherServlet] in context with path [/fidzit] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "home/home", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause 
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "home/home", template might not exist or might not be accessible by any of the configured Template Resolvers 
at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:246) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1011) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE] 
at 
[...] 

답변

1

당신은 템플릿 디렉토리에 대한 적절한 이름을 선택해야합니다 template 또는 templates. 여기

봐 : 여기

resolver.setPrefix("templates/"); 

과 :

/src 
--/main 
----/resources 
------/template 
관련 문제