Spring 配置context:component-scan产生的错误

在使用Spring 4.3.13并进行注解配置时遇到了bean配置错误。解决方法包括在schemaLocation中指定版本号以符合约束,或者在MyEclipse 2017中进行项目清理、XML文件验证设置的调整,以取消XML文件的约束验证。这些操作有助于消除Spring配置中的异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  在使用注解的方式配置bean遇到如下问题。

Referenced file contains errors (http://www.springframework.org/schema/beans/spring-beans-4.3.xsd). 
For more information, right click on the message in the Problems View and select "Show Details..."      

这里写图片描述

Spring是使用 maven 配置的4.3.13版本。


解决方式一 :
  schemaLocation的xsd约束加上当前版本号,我的是4.3版本,改为如下约束 。其余约束也最好加上版本号。

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

如图错误消失:
这里写图片描述


解决方式二:
  我的是MyEclipse 2017 并没有一下解决方式
    Progect –>clean
    Preferences -> General -> Network Connections -> Cache
    Preferences > XML > XML Files > Validation中”Honour all XML schema locations

  解决方式如图 :
这里写图片描述

  该方式是取消xml文件的约束验证。
  后面的setting方式可以设置相关的rules,不得其然也,如有大佬知道,还请指点。


附约束:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:context="http://www.springframework.org/schema/context"    
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
    xmlns:p="http://www.springframework.org/schema/p"          
    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/tx 
            http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd">


</beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值