Exception encountered during context initialization - cancelling refresh attempt:
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
上面的错误提示为nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException,
经查看是因为我的jdk版本不兼容,我当前的jdk版本为11。而引入的@enableAuthorizationServer在jdk8下可以完美运行,jdk11并没有兼容这个注解,因此会报这个错误。
在这个项目的pom.xml中引入下面三个依赖解决jdk11的兼容问题
<!--下面三个适配jdk11兼容性问题-->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.activation/activation -->
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.0-b170127.1453</version>
</dependency>
此解决方案只适用于jdk版本不兼容产生的这个问题,如果不符合这个大前提,该解决方案不一定适用哦~