2014-11-30 11 views
7

Buon giorno, ho appena creato un progetto per utilizzare Spring-boot e thymeleaf. Sto cercando di sfruttare il dialetto del layout per sfruttare le sue "tessere come il templating". Ho cercato questo problema e ogni risposta mi consiglia di aggiungere il dialetto di layout come un file di configurazione di avvio a molla. ma ogni tentativo che ho avuto a questo è fallito, il più recente è venuto da questo link How do I add a thymeleaf dialect to spring boot?. così ho aggiunto questo nel file di configurazionecome aggiungere il dialetto di layout al file di configurazione automatica spring-boot thymeleaf

@Configuration 
 
public class ThymleafConfiguration { 
 
\t @Bean 
 
\t public LayoutDialect layoutDialect() { 
 
\t \t return new LayoutDialect(); 
 
\t } 
 
}

ma risulta sempre con:

layout.html "Errore nella risoluzione template "", modello potrebbe non esiste o non potrebbe essere accessibile da uno qualsiasi dei Template Resolver configurati (welcomeHome: 4) "

tuttavia il file layout.html si trova nella cartella/resources/templates, quindi so che non è un disallineamento di posizione. Il mio obiettivo è solo quello di aggiungere il layout Dialect senza interrompere troppo le impostazioni di autoconfigurazione del boot di primavera. il mio pom ha entrambe le dipendenze di base del dialetto e del thymeleaf.

welcomeHome.html 
 
    <html xmlns="http://www.w3.org/1999/xhtml" 
 
     xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" 
 
     layout:decorator="layout.html"> 
 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

stack trace:

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "layout.html", template might not exist or might not be accessible by any of the configured Template Resolvers (welcomeHome:4) 
    at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:245) 
    at nz.net.ultraq.thymeleaf.decorator.DecoratorProcessor.processAttribute(DecoratorProcessor.java:92) 
    at org.thymeleaf.processor.attr.AbstractAttrProcessor.doProcess(AbstractAttrProcessor.java:87) 
    at org.thymeleaf.processor.AbstractProcessor.process(AbstractProcessor.java:212) 
    at org.thymeleaf.dom.Node.applyNextProcessor(Node.java:1016) 
    at org.thymeleaf.dom.Node.processNode(Node.java:971) 
    at org.thymeleaf.dom.NestableNode.computeNextChild(NestableNode.java:672) 
    at org.thymeleaf.dom.NestableNode.doAdditionalProcess(NestableNode.java:655) 
    at org.thymeleaf.dom.Node.processNode(Node.java:990) 
    at org.thymeleaf.dom.Document.process(Document.java:93) 
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1155) 
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060) 
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1011) 
    at org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:335) 
    at org.thymeleaf.spring4.view.ThymeleafView.render(ThymeleafView.java:190) 
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1221) 
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005) 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952) 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870) 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) 
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:620) 
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) 
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:201) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) 
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) 
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) 
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736) 
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1695) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
    at java.lang.Thread.run(Thread.java:745) 


 

 
    <?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" 
 
    \t xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
 
    \t <modelVersion>4.0.0</modelVersion> 
 

 
    \t <groupId>org.worksBeyond</groupId> 
 
    \t <artifactId>worksBeyondv2</artifactId> 
 
    \t <version>0.0.1-SNAPSHOT</version> 
 
    \t <packaging>war</packaging> 
 

 
    \t <name>WorksBeyond</name> 
 
    \t <description>A base project for works beyond</description> 
 

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

 
    \t <dependencies> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework.boot</groupId> 
 
    \t \t \t <artifactId>spring-boot-starter-security</artifactId> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework.boot</groupId> 
 
    \t \t \t <artifactId>spring-boot-starter-aop</artifactId> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework.boot</groupId> 
 
    \t \t \t <artifactId>spring-boot-starter-web</artifactId> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework.boot</groupId> 
 
    \t \t \t <artifactId>spring-boot-starter-thymeleaf</artifactId> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>nz.net.ultraq.thymeleaf</groupId> 
 
    \t \t \t <artifactId>thymeleaf-layout-dialect</artifactId> 
 
    \t \t </dependency> 
 
    \t <dependency> 
 
    \t \t \t <groupId>org.springframework.boot</groupId> 
 
    \t \t \t <artifactId>spring-boot-starter-social-facebook</artifactId> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework.boot</groupId> 
 
    \t \t \t <artifactId>spring-boot-starter-social-linkedin</artifactId> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework.boot</groupId> 
 
    \t \t \t <artifactId>spring-boot-starter-social-twitter</artifactId> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework.boot</groupId> 
 
    \t \t \t <artifactId>spring-boot-starter-tomcat</artifactId> 
 
    \t \t \t <scope>provided</scope> 
 
    \t \t </dependency> 
 
    \t \t <dependency> 
 
    \t \t \t <groupId>org.springframework.boot</groupId> 
 
    \t \t \t <artifactId>spring-boot-starter-test</artifactId> 
 
    \t \t \t <scope>test</scope> 
 
    \t \t </dependency> 
 
    \t <!-- <dependency> 
 
       <groupId>javax.servlet</groupId> 
 
       <artifactId>jstl</artifactId> 
 
      </dependency> --> 
 
    \t \t <dependency> 
 
       <groupId>org.springframework</groupId> 
 
       <artifactId>spring-context</artifactId> 
 
      </dependency> 
 
      <dependency> 
 
       <groupId>org.springframework</groupId> 
 
       <artifactId>spring-tx</artifactId> 
 
      </dependency> 
 
      <dependency> 
 
       <groupId>org.springframework.data</groupId> 
 
       <artifactId>spring-data-neo4j</artifactId> 
 
      </dependency> 
 
      <dependency> 
 
       <groupId>org.hibernate</groupId> 
 
       <artifactId>hibernate-validator</artifactId> 
 
      </dependency> 
 
    \t </dependencies> 
 

 
    \t <properties> 
 
    \t \t <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
 
    \t \t <start-class>worksBeyond.Application</start-class> 
 
    \t \t <java.version>1.7</java.version> 
 
    \t </properties> 
 

 
    \t <build> 
 
    \t \t <plugins> 
 
    \t \t \t <plugin> 
 
    \t \t \t \t <groupId>org.springframework.boot</groupId> 
 
    \t \t \t \t <artifactId>spring-boot-maven-plugin</artifactId> 
 
    \t \t \t </plugin> 
 
    \t \t </plugins> 
 
    \t </build> 
 
    \t 
 
    \t <repositories> 
 
      <repository> 
 
       <id>spring-releases</id> 
 
       <name>Spring Releases</name> 
 
       <url>https://repo.spring.io/libs-release</url> 
 
      </repository> 
 
      <repository> 
 
       <id>neo4j</id> 
 
       <name>Neo4j</name> 
 
       <url>http://m2.neo4j.org/</url> 
 
      </repository> 
 
     </repositories> 
 

 
     <pluginRepositories> 
 
      <pluginRepository> 
 
       <id>spring-releases</id> 
 
       <name>Spring Releases</name> 
 
       <url>https://repo.spring.io/libs-release</url> 
 
      </pluginRepository> 
 
     </pluginRepositories> 
 

 
    </project>

risposta

15

OK! quindi ho capito la soluzione. Il problema riguardava il nome del decoratore nel risolutore di viste. Così nel welcomeHome.html dichiarazione decoratore originale era:

welcomeHome.html 
 
    <html xmlns="http://www.w3.org/1999/xhtml" 
 
     xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" 
 
     layout:decorator="layout.html"> 
 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

La soluzione di lavoro è:

<html xmlns="http://www.w3.org/1999/xhtml" 
 
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" 
 
    layout:decorator="layout"> 
 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

La differenza sta nel omettendo il ".html" alla fine di layout.html. Così

disposizione: decoratore = "layout.html"

diventa:

disposizione: decoratore = "layout"

Da quello che ora sto capendo, il thymeleafautoconfiguration imposta il suffisso .html . il che significa che non è necessario aggiungerlo nel nome del file del decoratore.

+0

corretto. Oppure puoi modificare il suffisso in "spring.thymeleaf.suffix". –

+1

right.E per chiunque stia leggendo ciò che utilizza l'avvio a molla: è possibile modificare le impostazioni predefinite comuni nel file application.properties fornito con l'applicazione di avvio a molla. Questo è il punto in cui andresti a sovrascrivere il suffisso di thymeleaf (la posizione della vista) e il prefisso (l'estensione sulla vista cioè: .html, .jsp, ecc.) qui puoi trovare un elenco di proprietà comuni: http : //docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html –

0

Il LayoutDialect è già configurato automaticamente, quindi non dovrebbe essere necessario t o fai qualsiasi cosa Sei sicuro che "templates/layout.html" sia effettivamente sul classpath?

+0

E questo è quello che pensavo anche Dave.La mia unica certezza di trovarsi sul classpath è che quando lo carico senza il decoratore di layout, il thymeleaf risolve correttamente la vista. Il fatto che spring-boot dovrebbe autoconfigurare il bean una volta che nel mio Pom.xml lo rende un po 'più problematico. –

Problemi correlati