2014-12-04 63 views
2

我很累人在我的項目中使用spring boot,thymeleaf和瓷磚,但我只是不斷得到標題錯誤。
java.lang.IllegalArgumentException:找不到工廠來創建請求上下文

堆棧跟蹤誤差

java.lang.IllegalArgumentException: Cannot find a factory to create the request context 
    at org.apache.tiles.context.ChainedTilesRequestContextFactory.createRequestContext(ChainedTilesRequestContextFactory.java:137) 
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:317) 
    at org.thymeleaf.extras.tiles2.spring4.web.view.ThymeleafTilesView.render(ThymeleafTilesView.java:125) 
    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.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(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
    at java.lang.Thread.run(Unknown Source) 

我的pom.xml

<parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.1.9.RELEASE</version> 
     <relativePath /> 
    </parent> 
    <groupId>Supporter</groupId> 
    <artifactId>Supporter</artifactId> 
    <version>1.0</version> 
    <packaging>war</packaging> 
    <name>Supporter</name> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <start-class>com.test.supporter.Application</start-class> 
     <java.version>1.7</java.version> 
     <main.basedir>${basedir}/../..</main.basedir> 
     <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot> 
     <thymeleaf.version>2.1.3.RELEASE</thymeleaf.version> 
     <tiles.version>2.2.2</tiles.version> 
    </properties> 
    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.thymeleaf</groupId> 
      <artifactId>thymeleaf-spring4</artifactId> 
      <version>${thymeleaf.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.thymeleaf</groupId> 
      <artifactId>thymeleaf</artifactId> 
      <version>${thymeleaf.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.thymeleaf.extras</groupId> 
      <artifactId>thymeleaf-extras-tiles2-spring4</artifactId> 
      <version>2.1.1.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>jstl</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-tomcat</artifactId> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.tomcat.embed</groupId> 
      <artifactId>tomcat-embed-jasper</artifactId> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.tiles</groupId> 
      <artifactId>tiles-extras</artifactId> 
      <version>${tiles.version}</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 

的CONFIGRATION類

@Configuration 
public class Configurations { 

    @Bean 
    public SpringTemplateEngine templateEngine() { 
     SpringTemplateEngine templateEngine = new SpringTemplateEngine(); 
     Set<TemplateResolver> templateResolvers = new java.util.HashSet<>(); 
     templateResolvers.add(webTemplateResolver()); 
     templateEngine.setTemplateResolvers(templateResolvers); 
     Set<IDialect> additionalDialects = new HashSet<>(); 
     additionalDialects.add(new TilesDialect()); 
     templateEngine.setAdditionalDialects(additionalDialects); 
     return templateEngine; 
    } 

    @Bean 
     public ServletContextTemplateResolver webTemplateResolver() { 
      ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(); 
      templateResolver.setPrefix("WEB-INF/tiles/templates/"); 
      templateResolver.setSuffix(".html"); 
      templateResolver.setTemplateMode("HTML5"); 
      templateResolver.setCharacterEncoding("UTF-8"); 
      templateResolver.setOrder(2); 
      return templateResolver; 
     } 
    @Bean 
    public TilesConfigurer tilesConfigurer() { 
     final TilesConfigurer configurer = new TilesConfigurer(); 
     configurer.setDefinitions(new String[] { "WEB-INF/tiles/tiles-defs.xml" }); 
     configurer.setCheckRefresh(true); 
     return configurer; 
    } 
    @Bean 
    public TilesViewResolver tilesViewResolver() { 
     final TilesViewResolver resolver = new TilesViewResolver(); 
     resolver.setViewClass(TilesView.class); 
     return resolver; 
    } 
    @Bean 
    public ThymeleafViewResolver viewResolver() { 
     ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); 
     viewResolver.setViewClass(ThymeleafTilesView.class); 
     viewResolver.setTemplateEngine(templateEngine()); 
     viewResolver.setCharacterEncoding("UTF-8"); 
     viewResolver.setOrder(0);//ADDED LINE 
     return viewResolver; 
    } 

需要注意的是:還我試圖改變的版本圖書館,但我得到NoClassDefError並嘗試spring-boot-starter-thymeleaf但沒有運氣.so可以任何人幫助嗎?

+0

可以添加堆棧跟蹤? – 2014-12-04 09:35:50

+0

@RishiKeshPathak謝謝你的迴應我只是加了它 – 2014-12-04 09:38:28

+0

在pom.xml中缺少'tiles-core','tiles-template','tiles-jsp'和'tiles-servlet'依賴項? – 2014-12-04 09:44:57

回答

2

您使用的是的TilesConfigurer類配置一個thymeleaf瓷磚整合,的TilesConfigurer用於配置和春天有個磚整合只 所以要配置一個thymeleaf瓷磚Spring集成你應該的TilesConfigurer更改爲ThymeleafTilesConfigurer是在org.thymeleaf.extras.tiles2.spring4.web.configurer

因此你的方法應該改變,以

@Bean 
    public ThymeleafTilesConfigurer thymeleafTilesConfigurer(){ 
     final ThymeleafTilesConfigurer configurer = new ThymeleafTilesConfigurer(); 
     configurer.setDefinitions(new String[] { "WEB-INF/tiles/tiles-defs.xml" }); 
     configurer.setCheckRefresh(true); 
     return configurer; 
    } 

希望這就是幫助

+0

糟糕,我還沒有意識到這一點,非常感謝它的工作就像一個魅力現在:) – 2014-12-04 13:15:08

相關問題