我是Spring Boot的新手。我正在使用spring boot 1.5.1
,springSecurityVersion 3.2.3
和org.thymeleaf.extras:thymeleaf-extras-springsecurity4
版本,但是却遇到了异常
java.lang.ClassNotFoundException: org.springframework.security.core.context.SecurityContextHolder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_121]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_121]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_121]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_121]
at org.thymeleaf.extras.springsecurity4.auth.AuthUtils.getAuthenticationObject(AuthUtils.java:95) ~[thymeleaf-extras-springsecurity4-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect.getAdditionalExpressionObjects(SpringSecurityDialect.java:117) ~[thymeleaf-extras-springsecurity4-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.thymeleaf.context.AbstractDialectAwareProcessingContext.computeExpressionObjects(AbstractDialectAwareProcessingContext.java:113) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.thymeleaf.context.AbstractProcessingContext.getExpressionObjects(AbstractProcessingContext.java:132) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.thymeleaf.spring4.expression.SpelVariableExpressionEvaluator.computeExpressionObjects(SpelVariableExpressionEvaluator.java:197) ~[thymeleaf-spring4-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.thymeleaf.spring4.expression.SpelVariableExpressionEvaluator.evaluate(SpelVariableExpressionEvaluator.java:115) ~[thymeleaf-spring4-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.thymeleaf.standard.expression.VariableExpression.executeVariable(VariableExpression.java:154) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE]
at org.thymeleaf.standard.expression.SimpleExpression.executeSimple(SimpleExpression.java:59) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE
我的配置有什么错误?
答案 0 :(得分:0)
如问题中所述,您正在使用Spring Security 3.2.3,但也使用thymeleaf-extras-springsecurity4
依赖项,该依赖项仅适用于Spring Security 4.x。
由于这种不兼容,Thymeleaf依赖项无法找到某些类,这就是为什么它抛出ClassNotFoundException
的原因。
解决方案是使用以下任一兼容的库:
将Thymeleaf依赖项降级为thymeleaf-extras-springsecurity3
,例如,在使用Maven时:
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity3</artifactId>
</dependency>