我使用Spring启动,我想使用磁贴,但我有一个问题:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.thymeleaf.spring4.SpringTemplateEngine]: Factory method 'getTemplateEngine' threw exception; nested exception is java.lang.NoSuchMethodError: org.thymeleaf.dialect.AbstractDialect: method <init>()V not found
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
... 18 common frames omitted
Caused by: java.lang.NoSuchMethodError: org.thymeleaf.dialect.AbstractDialect: method <init>()V not found
at org.thymeleaf.extras.tiles2.dialect.TilesDialect.<init>(TilesDialect.java:46) ~[thymeleaf-extras-tiles2-2.1.1.RELEASE.jar:na]
at com.scheduler.config.mvc.MvcConfiguration.getTemplateEngine(MvcConfiguration.java:39) ~[classes/:na]
at com.scheduler.config.mvc.MvcConfiguration$$EnhancerBySpringCGLIB$$7a5dfe74.CGLIB$getTemplateEngine$1(<generated>) ~[classes/:na]
at com.scheduler.config.mvc.MvcConfiguration$$EnhancerBySpringCGLIB$$7a5dfe74$$FastClassBySpringCGLIB$$41c485b2.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at com.scheduler.config.mvc.MvcConfiguration$$EnhancerBySpringCGLIB$$7a5dfe74.getTemplateEngine(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_80]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_80]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_80]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_80]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
我的部分WebMvcConfigurerAdapter:
@Bean(name = "templateResolver")
public SpringResourceTemplateResolver getTemplateResolver() {
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setPrefix("/WEB-INF/views/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML");
templateResolver.setCacheable(false);
return templateResolver;
}
@Bean(name = "templateEngine")
public SpringTemplateEngine getTemplateEngine(SpringResourceTemplateResolver resolver) {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(resolver);
templateEngine.addDialect(new SpringSecurityDialect());
templateEngine.addDialect(new TilesDialect());
return templateEngine;
}
@Bean(name = "viewResolver")
public ThymeleafViewResolver getViewResolver(SpringTemplateEngine templateEngine) {
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine);
viewResolver.setCharacterEncoding("UTF-8");
viewResolver.setOrder(Ordered.HIGHEST_PRECEDENCE);
viewResolver.setExcludedViewNames(new String[]{"*"});
return viewResolver;
}
当执行波纹管线时,上面的异常是抛出:
templateEngine.addDialect(new TilesDialect());
pom.xml依赖项:
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.1.0.RELEASE</version>
</dependency>
<!-- Thymeleaf -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-tiles2-spring4</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity3</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
</dependencies>
你可以帮帮我吗?
谢谢!
答案 0 :(得分:3)
这是因为全新的Thymeleaf 3.0.0.RELEASE
尚不支持Tiles。您必须等待更新thymeleaf-extras-tiles2-spring4
回到Thymeleaf 2或从Tiles辞职:P
答案 1 :(得分:0)
我在spring-social和thymeleaf 3.0.3之间的整合方面遇到了一些问题。
我的解决方案:
1)从模块的autoConfiguration中排除模块(在我的情况下是spring-social):
@SpringBootApplication
@EnableAutoConfiguration(exclude = {SocialWebAutoConfiguration.class})
public class MyApplication { ...
2)创建配置类:
@EnableSocial
@Configuration
public class SocialConfig implements SocialConfigurer {
...
}
3)覆盖ModuleDialect类(对我来说:SpringSocialDialect.class):
public class CustomSpringSocialDialect extends AbstractDialect {
public CustomSpringSocialDialect() {
super("social");
}
public String getPrefix() {
return "soc";
}
public Set<IProcessor> getProcessors() {
return new SpringSocialDialect().getProcessors();
}
}
4)在MvcConfig.class中添加方言到templateEngine:
@Bean
public SpringTemplateEngine templateEngine(ITemplateResolver templateResolver) {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
templateEngine.addDialect(new SpringSecurityDialect());
templateEngine.addDialect(new CustomSpringSocialDialect());
templateEngine.addDialect(new Java8TimeDialect());
templateEngine.setMessageSource(messageSource());
return templateEngine;
}
我认为你的问题就是这个方向。所以你的 TilesDialect 有构造函数而没有arg它是你的问题。之后你可以使用最新版本的百里香[/ p>]