解决spring-jpa.xsd无法读取的问题

stc8902 2013-10-31 10:05:28
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
">

<!-- 配置Spring Data JPA扫描目录

请注意这里的jpa标签会报错,提示无法读取到spring-jpa.xsd文件。虽然笔者已经在spring.schema文件

中配置了该uri是定位到spring-jpa-1.3.xsd,但依然无法读取

-->
<jpa:repositories base-package="repository"
entity-manager-factory-ref="entityManagerFactory"
transaction-manager-ref="transactionManager"/>
<jpa:auditing/>
</beans>



下面是报的错:



Multiple annotations found at this line:
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'jpa:repositories'.
- schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/data/jpa/spring-jpa.xsd', because 1) could
not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.



解决办法:

将 http://www.springframework.org/schema/data/jpa/spring-jpa.xsd 更换为 http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.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:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
">

<!-- 配置Spring Data JPA扫描目录-->
<jpa:repositories base-package="repository"
entity-manager-factory-ref="entityManagerFactory"
transaction-manager-ref="transactionManager"/>
<jpa:auditing/>
</beans>





此时问题并没有真正解决,eclipse会报另外一个错误



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

如果是eclipse 打开Marker 选择错误的地方点showdetails 如果是myeclipse 打开problem 同上。


图片不会弄 不知道传上来了没有

这是错误提示

The errors below were detected when validating the file "spring-jpa-1.3.xsd" via the file "applicationContext.xml". In most cases these errors can be detected by validating "spring-jpa-1.3.xsd" directly. However it is possible that errors will only occur when spring-jpa-1.3.xsd is validated in the context of applicationContext.xml.



这个错误后面 还有警告和错误信息,复制不了,不会传图。

解决办法

加上 http://www.springframework.org/schema/data/repository
http://www.springframework.org/schema/data/repository/spring-repository-1.6.xsd

注意这里的spring-repository-1.6.xsd不能写成spring-repository.xsd 。 不然会出现第一个错误,读取不到这个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:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/data/repository
http://www.springframework.org/schema/data/repository/spring-repository-1.6.xsd
">

<!-- 配置Spring Data JPA扫描目录-->
<jpa:repositories base-package="repository"
entity-manager-factory-ref="entityManagerFactory"
transaction-manager-ref="transactionManager"/>
<jpa:auditing/>
</beans>

问题到此终于解决,至于这个问题是因为什么引起的 笔者也不清楚。 因为有些人的电脑上是可以不用配置spring-repository.xsd的这个URI的。










...全文
1207 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
teemai 2013-10-31
  • 打赏
  • 举报
回复
看了半天,原来问题解决了

51,410

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧