您的位置:首页 > 编程语言 > Java开发

关于在Spring配置特殊bean-分散配置的时候抛出的异常:无法找到元素 'context:component-scan' 的声明 的解决方法

2017-09-01 15:47 633 查看
方法很简单,就是beans的声明xmlns和xsi:schemaLocation的时没有把xmlns:context相对应的那些配置声明上去。

解决方法:只需要在<beans>里面声明上去即可。

代码如下:

这个是直接在<beans>里面粘贴上去即可

xmlns:context="http://www.springframework.org/schema/context" 

然后这个则是在xsi:schemaLocation=" "里面粘贴进去

 http://www.springframework.org/schema/context 

 http://www.springframework.org/schema/context/spring-context.xsd"

例:我的是这样子的:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context.xsd" >

需要注意的是

  http://www.springframework.org/schema/context 

 http://www.springframework.org/schema/context/spring-context.xsd"

这两个要粘贴在一起,不要间插其他的语句也不要被其他语句间插,语句应该都是两句两句黏在一起的,就想这样

xsi:schemaLocation="  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context.xsd" 

不知道你们的会不会这样,反正我的如果换成这样  ↓  就会报错

xsi:schemaLocation=" 
 http://www.springframework.org/schema/beans

 http://www.springframework.org/schema/context
http://www.springframework.org/schema/beans/spring-beans.xsd 
 http://www.springframework.org/schema/context/spring-context.xsd" 

所以我觉得还是两两粘贴,不要分开比较好- -

仅为个人记事,大牛觉得有不对的地方,可以点出来帮我改正- -不喜勿喷喜请点赞。》》》》》》
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐