Java.lang.IllegalArgumentException: не удается найти фабрику для создания контекста запроса

Я устаю использовать весенний ботинок, тимелеаф и плитки в своем проекте, но я просто получаю титульную ошибку.

Ошибка stacktrace

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)

my pom.xml

<parent>
 <groupid>org.springframework.boot</groupid>
 <artifactid>spring-boot-starter-parent</artifactid>
 <version>1.1.9.RELEASE</version>
 <relativepath> 
 </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>

Класс конфигурации

@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;
 }
</idialect></templateresolver>

Обратите внимание, что: также я попытался изменить версии библиотек, но я получил NoClassDefError и попробовал spring-boot-starter-thymeleaf, но не повезло. Так может кто-нибудь помочь?

1 ответ

вы используете класс TilesConfigurer для настройки интеграции тимелеафа, TilesConfigurer используется для настройки интеграции плиток с пружиной, поэтому для настройки интеграции с плиточными плитами тимелеафа вы должны изменить 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;
 }

Надеюсь, что это помогает

licensed under cc by-sa 3.0 with attribution.