2016-05-14 121 views
1

我使用Spring的引导,我想用瓷砖,但我有一个问题:春季启动:TilesDialect()抛出异常

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> 

你能帮我吗? 谢谢!

回答

3

这是因为全新的Thymeleaf 3.0.0.RELEASE不支持Tiles。你必须等待更新thymeleaf-extras-tiles2-spring4回到Thymeleaf 2或像我一样从Tiles辞职:P

+0

感谢您的帮助:)我已经将百里香设置为“2.1.2.RELEASE”,它的工作! :) – Jacek

+0

任何消息什么时候会发布?这篇文章已经有十个月了 – Jake

0

我在spring-social和thymeleaf 3.0.3之间进行集成时遇到了一些问题。

我的解决办法:

1)自动配置排除模块模块(在我的处境弹簧社会):

@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)templateEngine加入方言MvcConfig.class:

@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的构造函数这是你的问题。之后,你可以使用最后的版本百里香