Spring报Context namespace element 'component-scan'... are only available on JDK 1.5 and higher解决问题

在使用阿里巴巴开源的分布式服务框架Dubbo与Spring进行整合时遇到兼容性问题,表现为启动时出现错误提示,通过排查发现是由旧版本的Spring依赖包引起的。

最近项目中用到了alibaba开源的分布式服务框架dubbo,与Spring整合的时候,启动报如下错误:

 org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [annotation.xml]; nested exception is java.lang.IllegalStateException: Context namespace element 'component-scan' and its parser class [org.springframework.context.annotation.ComponentScanBeanDefinitionParser] are only available on JDK 1.5 and higher
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)

抓住错误的重点描述,是开头这句:
Context namespace element ‘component-scan’ and its parser class … are only available on JDK 1.5 and higher

字面意思是JDK版本不对,网上大多数人都说,原因是引用的Spring版本太低(2.5或以下),那时候JDK1.8还没出来云云。只要提高一下Spring版本,或降低JDK版本,就解决了。

但我觉得问题并没有这么简单,因为现在为止,我碰到的问题从来没有这么快解决的。果不其然,我试了一下,两种方法都不行。

我的直觉告诉我,应该是依赖包的版本冲突了。因为dubbo依赖包是新引进来的,所以问题一定出在这货身上。我仔细检查了一下External Libraries中的依赖包,发现这个包很可疑
test1

这是什么鬼?你是来捣乱的吗?但是很抱歉,你伪装的太不专业了,被我发现了,嘿嘿!原因果然还是版本的问题,只不过是其他的问题导致的这个问题。需要层层去寻找问题的根源。

为了确定这货的确是dubbo包引进来的,我找到dubbo的pom.xml,点进去,果然找到了
test2

原来dubbo开源的时候是2011年,那时候的Spring版本只有这么高,后来dubbo官方团队又没有维护了(既然人家开源出来,肯定是用更好的解决方案替代了,而那些只会消费,不能创造的人,会一直落后于大佬,所以说创新是安身立命之本呀)。把dubbo的依赖项注掉之后,那个过时的Spring包自动去掉了,上面的错误也消失了。不过新的问题又来了,dubbo起不来了
test3

不过这又是另一段故事了……

评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值