Spring3.2环境下applicationContext.xml的bean标签使用primary属性报错问题
报错原因分析
这个报错属于IntelliJ IDEA的XML schema校验误报,你的配置本身没有功能性问题,项目可以正常启动运行,标红的触发原因分为两类:
- IntelliJ本地缓存的Spring
spring-beans.xsd文件损坏或者版本不匹配,导致IDEA无法识别primary属性 - 你配置的schemaLocation使用了无版本号的通用xsd地址,IDEA加载的最新版xsd和你实际使用的Spring 3.2版本存在微小规则差异,触发误判
解决方案
你可以根据自己的需求选择任意一种方案处理:
- 删掉无用的
primary属性:你的配置中已经通过<mvc:annotation-driven validator="validator"/>显式指定了MVC环境使用的校验器,没有多Validator实例注入冲突的场景下,primary属性本身就是多余的,删除后标红会直接消失,不影响任何功能 - 强制指定对应版本的xsd:把
xsi:schemaLocation中spring-beans的xsd地址改为和你Spring版本匹配的地址:http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.2.xsd - 清空IDEA缓存重启:打开IDEA菜单
File → Invalidate Caches...,勾选「Clear file system cache and local history」后点击「Invalidate and Restart」,重启后IDEA会重新加载项目的schema文件,校验误报就会消失
内容的提问来源于stack exchange,提问作者user10636910
相关产品推荐
相关产品推荐

