Spring Boot Security + Thymeleaf:缺少IProcessorDialect类

纪尧姆·普雷沃斯特(Guillaume Prevost)

我正在尝试将Thymeleaf安全方言(例如sec:authorize标签)集成到可以正常工作的Spring Boot + Spring Security应用程序中。

经过一番研究,我发现激活该问题的解决方案是:

在POM文件中添加依赖项:

<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-springsecurity4</artifactId>
    <version>3.0.0.RELEASE</version>
</dependency>

并在模板文件的顶部添加标签:

<html   xmlns:th="http://www.thymeleaf.org" lang="en"
        xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">

到目前为止,一切都很好。找到依赖关系,在标记中识别出标签。

但是,它们并未考虑在内,并出现在最终生成的HTML中。

由于无法启动Spring Boot自动配置中的问题,因此似乎有必要将SpringSecurityDialect Bean手动添加到一个@Configuration类中以启用它(在StackOverflow上发现的几个问题已通过此方法解决):

@Bean
    public SpringSecurityDialect securityDialect() {
        return new SpringSecurityDialect();
    }

这就是导致问题的原因:当我将此Bean添加到我的Spring Boot Configuration中时,它会引发一个异常,因为它找不到类org.thymeleaf.dialect.IProcessorDialect这是错误:

> java.lang.IllegalStateException: Could not evaluate condition on
> org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer
> due to org/thymeleaf/dialect/IProcessorDialect not found. Make sure
> your own configuration does not rely on that class. This can also
> happen if you are @ComponentScanning a springframework package (e.g.
> if you put a @ComponentScan in the default package by mistake)

我想念什么?这是Thymeleaf的错误吗?春季靴?我自己的代码?在此先感谢您的帮助 !

这是我的问题所涉及的一些文件:

应用程序

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
      public EmbeddedServletContainerFactory servletContainer() {
        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
            @Override
            protected void postProcessContext(Context context) {
              SecurityConstraint securityConstraint = new SecurityConstraint();
              securityConstraint.setUserConstraint("CONFIDENTIAL");
              SecurityCollection collection = new SecurityCollection();
              collection.addPattern("/*");
              securityConstraint.addCollection(collection);
              context.addConstraint(securityConstraint);
            }
          };

        tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
        return tomcat;
      }

      private Connector initiateHttpConnector() {
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setScheme("http");
        connector.setPort(8080);
        connector.setSecure(false);
        connector.setRedirectPort(8443);

        return connector;
      }
}

WebMvcConfig.java

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect;

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    /**
     * Configure relationships between URLs and view names
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
    }

    @Bean
    public SpringSecurityDialect securityDialect() {
        return new SpringSecurityDialect();
    }
}

胸腺模板:

<!DOCTYPE html>
<html   xmlns:th="http://www.thymeleaf.org" lang="en"
        xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">

....

<div sec:authorize="isAuthenticated()">
    LOGGED IN
</div>
<div sec:authorize="isAnonymous()">
    ANONYMOUS
</div>

....

启动应用程序时的完整控制台输出:

>  :: Spring Boot ::        (v1.3.4.RELEASE)
> 
> 2016-05-17 17:22:59.951  INFO 96267 --- [  restartedMain]
> edu.rmit.eres.estored.Application        : Starting Application on
> w8031808.local with PID 96267
> (/Users/guillaume/dev/workspace/e-stored/target/classes started by
> guillaume in /Users/guillaume/dev/workspace/e-stored) 2016-05-17
> 17:22:59.956  INFO 96267 --- [  restartedMain]
> edu.rmit.eres.estored.Application        : No active profile set,
> falling back to default profiles: default 2016-05-17 17:23:00.239 
> INFO 96267 --- [  restartedMain]
> ationConfigEmbeddedWebApplicationContext : Refreshing
> org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@16f53cde:
> startup date [Tue May 17 17:23:00 AEST 2016]; root of context
> hierarchy 2016-05-17 17:23:01.578 ERROR 96267 --- [  restartedMain]
> o.s.boot.SpringApplication               : Application startup failed
> 
> java.lang.IllegalStateException: Could not evaluate condition on
> org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer
> due to org/thymeleaf/dialect/IProcessorDialect not found. Make sure
> your own configuration does not rely on that class. This can also
> happen if you are @ComponentScanning a springframework package (e.g.
> if you put a @ComponentScan in the default package by mistake)    at
> org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:55)
> ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
> org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:102)
> ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
> org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:178)
> ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
> org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:140)
> ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
> org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116)
> ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
> org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:333)
> ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
> org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
> ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
> org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273)
> ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
> org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98)
> ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
> org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678)
> ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520)
> ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]     at
> org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
> ~[spring-boot-1.3.4.RELEASE.jar:1.3.4.RELEASE]    at
> org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)
> [spring-boot-1.3.4.RELEASE.jar:1.3.4.RELEASE]     at
> org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)
> [spring-boot-1.3.4.RELEASE.jar:1.3.4.RELEASE]     at
> org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
> [spring-boot-1.3.4.RELEASE.jar:1.3.4.RELEASE]     at
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
> [spring-boot-1.3.4.RELEASE.jar:1.3.4.RELEASE]     at
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
> [spring-boot-1.3.4.RELEASE.jar:1.3.4.RELEASE]     at
> edu.rmit.eres.estored.Application.main(Application.java:24)
> [classes/:na]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method) ~[na:1.8.0_60]    at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> ~[na:1.8.0_60]    at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> ~[na:1.8.0_60]    at java.lang.reflect.Method.invoke(Method.java:497)
> ~[na:1.8.0_60]    at
> org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
> [spring-boot-devtools-1.3.4.RELEASE.jar:1.3.4.RELEASE] Caused by:
> java.lang.NoClassDefFoundError:
> org/thymeleaf/dialect/IProcessorDialect   at
> java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_60]  at
> java.lang.ClassLoader.defineClass(ClassLoader.java:760) ~[na:1.8.0_60]
>   at
> java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
> ~[na:1.8.0_60]    at
> java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
> ~[na:1.8.0_60]    at
> java.net.URLClassLoader.access$100(URLClassLoader.java:73)
> ~[na:1.8.0_60]    at
> java.net.URLClassLoader$1.run(URLClassLoader.java:368) ~[na:1.8.0_60]
>   at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
> ~[na:1.8.0_60]    at java.security.AccessController.doPrivileged(Native
> Method) ~[na:1.8.0_60]    at
> java.net.URLClassLoader.findClass(URLClassLoader.java:361)
> ~[na:1.8.0_60]    at
> java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_60]
>   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
> ~[na:1.8.0_60]    at
> java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
>   at
> org.springframework.boot.devtools.restart.classloader.RestartClassLoader.loadClass(RestartClassLoader.java:151)
> ~[spring-boot-devtools-1.3.4.RELEASE.jar:1.3.4.RELEASE]   at
> java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
>   at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_60]
>   at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
> ~[na:1.8.0_60]    at java.lang.Class.getDeclaredMethods(Class.java:1975)
> ~[na:1.8.0_60]    at
> org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:612)
> ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE]    at
> org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
> ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE]    at
> org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510)
> ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE]    at
> org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:570)
> ~[spring-core-4.2.6.RELEASE.jar:4.2.6.RELEASE]    at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:683)
> ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]   at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:627)
> ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]   at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:597)
> ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]   at
> org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1445)
> ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]   at
> org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:975)
> ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]   at
> org.springframework.boot.autoconfigure.condition.BeanTypeRegistry$OptimizedBeanTypeRegistry.addBeanTypeForNonAliasDefinition(BeanTypeRegistry.java:289)
> ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
> org.springframework.boot.autoconfigure.condition.BeanTypeRegistry$OptimizedBeanTypeRegistry.addBeanType(BeanTypeRegistry.java:278)
> ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
> org.springframework.boot.autoconfigure.condition.BeanTypeRegistry$OptimizedBeanTypeRegistry.getNamesForType(BeanTypeRegistry.java:259)
> ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
> org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:182)
> ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
> org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:171)
> ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
> org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:139)
> ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
> org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:113)
> ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  at
> org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)
> ~[spring-boot-autoconfigure-1.3.4.RELEASE.jar:1.3.4.RELEASE]  ... 22
> common frames omitted Caused by: java.lang.ClassNotFoundException:
> org.thymeleaf.dialect.IProcessorDialect   at
> java.net.URLClassLoader.findClass(URLClassLoader.java:381)
> ~[na:1.8.0_60]    at
> java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_60]
>   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
> ~[na:1.8.0_60]    at
> java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
>   ... 56 common frames omitted
> 
> 2016-05-17 17:23:01.581  INFO 96267 --- [  restartedMain]
> .b.l.ClasspathLoggingApplicationListener : Application failed to start
> with classpath:
> [file:/Users/guillaume/dev/workspace/e-stored/target/classes/]
纪尧姆·普雷沃斯特(Guillaume Prevost)

感谢Deinum先生的有用评论!

确实确实不支持“ 3.0.0版的Thymeleaf Extras for Spring Security 4”。

我已经将POM文件中Thymeleaf thymeleaf-extras-springsecurity4的Maven依赖版本从3.0.0更改为最新的2.xx版本(在本文发布时为2.1.2),并且此问题已解决。

从:

    <!-- http://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity4 -->
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        <version>3.0.0.RELEASE</version>
    </dependency>

到:

    <!-- http://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity4 -->
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        <version>2.1.2.RELEASE</version>
    </dependency>

问题不再出现,Web应用程序正常启动,并且可以识别标签:)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Spring Boot + Security + Thymeleaf和CSRF令牌不会自动注入

来自分类Dev

Thymeleaf Security不适用于Spring Boot 1.3.5

来自分类Dev

Spring Boot,Spring Security和Thymeleaf:使用表单将CsrfFilter应用于网站

来自分类Dev

Spring Boot或Spring Security内存可能泄漏

来自分类Dev

Spring Boot ServeletInitializer和Spring Security

来自分类Dev

Spring Boot中Spring Security的XML配置

来自分类Dev

使用Spring Boot配置Spring Security

来自分类Dev

Spring Boot或Spring Security内存可能泄漏

来自分类Dev

带有Spring Boot的Spring Security

来自分类Dev

Spring Boot Security-Thymeleaf sec:authorize-url不起作用

来自分类Dev

Spring Boot Security:如何在没有Thymeleaf的情况下访问$ {param.error}?

来自分类Dev

Spring Boot Security-Thymeleaf sec:authorize-url不起作用

来自分类Dev

how to implement a authentication with spring boot security?

来自分类Dev

Spring Boot Security 403重定向

来自分类Dev

Spring Boot + Security + JWT 无法生成token

来自分类Dev

Thymeleaf的Spring Security的简单示例

来自分类Dev

Spring Boot / Spring Security正在忽略来自JavaScript的/ login调用

来自分类Dev

使用AspectJ的Spring Boot + Spring Security无法正常工作

来自分类Dev

Spring Security / Spring Boot-如何为用户设置ROLES

来自分类Dev

spring-boot,spring-security和dropwizard指标

来自分类Dev

如何在Spring Boot中覆盖Spring Security默认配置

来自分类Dev

从Spring Boot Oauth2迁移到Spring Security 5

来自分类Dev

没有Spring Security的Spring-Boot登录

来自分类Dev

Spring Boot-如何终止当前的Spring Security会话?

来自分类Dev

如何使用 Spring Security 在 Spring Boot 中管理会话?

来自分类Dev

Spring Boot、Spring Security - 防止 MongoDB 的直接 URL 查询

来自分类Dev

Spring Boot类路径

来自分类Dev

Spring boot 类行为

来自分类Dev

用户类的Spring Security应用

Related 相关文章

  1. 1

    Spring Boot + Security + Thymeleaf和CSRF令牌不会自动注入

  2. 2

    Thymeleaf Security不适用于Spring Boot 1.3.5

  3. 3

    Spring Boot,Spring Security和Thymeleaf:使用表单将CsrfFilter应用于网站

  4. 4

    Spring Boot或Spring Security内存可能泄漏

  5. 5

    Spring Boot ServeletInitializer和Spring Security

  6. 6

    Spring Boot中Spring Security的XML配置

  7. 7

    使用Spring Boot配置Spring Security

  8. 8

    Spring Boot或Spring Security内存可能泄漏

  9. 9

    带有Spring Boot的Spring Security

  10. 10

    Spring Boot Security-Thymeleaf sec:authorize-url不起作用

  11. 11

    Spring Boot Security:如何在没有Thymeleaf的情况下访问$ {param.error}?

  12. 12

    Spring Boot Security-Thymeleaf sec:authorize-url不起作用

  13. 13

    how to implement a authentication with spring boot security?

  14. 14

    Spring Boot Security 403重定向

  15. 15

    Spring Boot + Security + JWT 无法生成token

  16. 16

    Thymeleaf的Spring Security的简单示例

  17. 17

    Spring Boot / Spring Security正在忽略来自JavaScript的/ login调用

  18. 18

    使用AspectJ的Spring Boot + Spring Security无法正常工作

  19. 19

    Spring Security / Spring Boot-如何为用户设置ROLES

  20. 20

    spring-boot,spring-security和dropwizard指标

  21. 21

    如何在Spring Boot中覆盖Spring Security默认配置

  22. 22

    从Spring Boot Oauth2迁移到Spring Security 5

  23. 23

    没有Spring Security的Spring-Boot登录

  24. 24

    Spring Boot-如何终止当前的Spring Security会话?

  25. 25

    如何使用 Spring Security 在 Spring Boot 中管理会话?

  26. 26

    Spring Boot、Spring Security - 防止 MongoDB 的直接 URL 查询

  27. 27

    Spring Boot类路径

  28. 28

    Spring boot 类行为

  29. 29

    用户类的Spring Security应用

热门标签

归档