1.JDK版本问题,之前配置啥的都没错但是却出现
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的兼容问题
<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版本不兼容产生的这个问题,如果不符合这个大前提,该解决方案不一定适用哦~
详情请看:https://blog.csdn.net/qq_37393900/article/details/103136461
下面是第二个坑:
2.文件重复加载问题
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file :
Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
后面改了JDK的版本(从11改到了8)还是出现了这个问题(JDK版本8向对于来说更为稳定兼容性更好)
该问题解决方案为
先看看我的配置文件错误的点:
XML的文件(图一)
spring.XML文件(图二)
图三
我猜测应该是文件重复加载的问题然后我就将图二的扫描全部mapper.XML的文件注掉然后就运行成功了