当前位置:编程学习 > JAVA >>

解决spring-jpa.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.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的。




 





jpa标签 spring-jpa.xsd jpa配置 --------------------编程问答-------------------- 看了半天,原来问题解决了
补充:Java ,  Java相关
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,