我出现这个问题的 SpringBoot 版本是 2.3.4,java 版本是 11
一、问题描述
对于springsecurity 的其他配置没出现什么问题,将其和 Oauth2 结合使用时,出现:
错误信息:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘springSecurityFilterChain’ defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method ‘springSecurityFilterChain’ threw exception; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
二、问题解决
问题的原因是:Java 11删除了Java EE模块: java.xml.bind (JAXB) - REMOVED
可以通过使用Java EE的替代版本来解决此问题。需要添加包含所需类的Maven依赖项,添加到 pom 文件中即可
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.2</version>
</dependency>
问题解决:
转载:https://blog.csdn.net/nanhuaibeian/article/details/108900564