将 Spring security 从3.1.1版本升级为5.4.1时,出现异常,异常信息如下。
19-Oct-2020 13:59:54.109 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.listenerStart 异常将上下文初始化事件发送到类的侦听器实例.[org.springframework.web.context.ContextLoaderListener]org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:spring/applicationContext-security.xml]Offending resource: class path resource [spring/applicationContext.xml];nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: You cannot use a spring-security-2.0.xsd or spring-security-3.0.xsd or spring-security-3.1.xsd schema or spring-security-3.2.xsd schema or spring-security-4.0.xsd schema with Spring Security 5.4. Please update your schema declarations to the 5.4 schema.Offending resource: class path resource [spring/applicationContext-security.xml]at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:72)at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:119)at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:104)at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:240)at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:191).........
查看我的security配置文件

发现配置里的版本和spring security的版本不一致。
解决方法:
1 直接省略不写版本号,交给spring自己去匹配对应的版本
2 指定和security相同的版本号
我选择第一种省略版本号的方法,再次编译启动 一切正常。