Java STS&x2B;Spring数据JPA+;Hibernate存储库XML配置问题

Java STS&x2B;Spring数据JPA+;Hibernate存储库XML配置问题,java,spring,jpa,spring-data,spring-tool-suite,Java,Spring,Jpa,Spring Data,Spring Tool Suite,我在STS中遇到了一个问题,它在引用jpa:repositories节点时在我的context.xml文件中显示了一个错误。它不会阻止应用程序运行(实际上似乎运行得很好),但我无法消除错误 错误: Error occured processing XML 'Class org/springframework/data/repository/config/RepositoryComponentProvider illegally accessing "package private" membe

我在STS中遇到了一个问题,它在引用jpa:repositories节点时在我的context.xml文件中显示了一个错误。它不会阻止应用程序运行(实际上似乎运行得很好),但我无法消除错误

错误:

Error occured processing XML 'Class
org/springframework/data/repository/config/RepositoryComponentProvider illegally 
accessing "package private" member of class org/springframework/context/
annotation/AnnotationConfigUtils'. See Error Log for more details
有问题的XML段:

<?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"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <tx:annotation-driven transaction-manager="transactionManagerSpecial" />
    <jpa:repositories base-package="com.testcompany.**.repository" transaction-manager-ref="transactionManagerSpecial"></jpa:repositories>
**根据以下回复更新Spring数据JPA 1.5.2**

更新到JPA1.5.2“可能”解决了上述问题(因为XML不再抱怨引用私有方法),但仍然存在引用问题。现在,我的存储库找不到JpaRepository引用的“分页和排序”存储库(尽管它可以找到JpaRepository本身):

**最终更新** 上面的问题是本地Maven存储库的问题。解决了这个问题后,我得到了一个干净的项目。。。除了jpa:repositories元素上的最后一个错误:

AnnotationConfigUtils.processCommonDefinitionAnnotations(…) is not public! Make sure you're using Spring 3.2.5 or better. The class was loaded from file:/C:/Program Files/STS/3.4/plugins/org.springframework.context_4.0.0.20130829-M3.jar.:org.springframework.context.annotation.AnnotationConfigUtils.processCommonDefinitionAnnotations(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)
经过一些搜索,我发现这可能是STS 3.4的一个问题:
我将升级到STS 3.5,看看它是否解决了这个问题。

这肯定是由于类路径设置不正确造成的。我们尝试使用的相关方法是Spring上下文中的
AnnotationConfigUtils.processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd)
。此方法已在版本3.2.5和4.0.0中公开。因此,如果您的类路径是按照您描述的那样设置的,则不会发生异常

我建议升级到较新版本的SpringDataJPA(1.5.2.RELEASE是本文撰写时的最新版本),因为我们引入了一个新的方法,用于提供比您当前得到的更好的异常


它可能是在旧版本中引入Spring JAR的其他库,但默认情况下,Spring数据项目肯定会引入与库兼容的Spring版本。

非常感谢您的反馈。我同意你可能是对的,尽管我无法找到“问题”可能发生的地方,因为就我所见,POM似乎是正确的。。。我上传了上面的POM(上面的一些名字为了保护无辜而改变)。你有没有发现什么明显的错误?pom本身是非常有限的。您介意添加
mvn dependency:tree
的输出吗?升级到前面提到的版本应该显式地指向有问题的JAR。上面添加的依赖项。再次感谢。更新到1.5.2可能已经解决了POM问题,但我仍然觉得存在依赖性问题。我在上面提供了更新。我认为JPA数据的更新解决了之前的问题(如上所述,以及我遇到的其他问题)。再次感谢您的帮助。请添加
mvn dependency:tree
的输出。
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ test-spring-transactional ---
[INFO] com.test.spring.template:test-spring-transactional:jar:1.0.1
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.3.5.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:4.3.5.Final:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.4.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] |  \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] +- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] +- org.springframework:spring-test:jar:4.0.2.RELEASE:test
[INFO] |  \- org.springframework:spring-core:jar:4.0.2.RELEASE:compile
[INFO] |     \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] +- org.springframework:spring-context-support:jar:4.0.2.RELEASE:compile
[INFO] |  \- org.springframework:spring-beans:jar:4.0.2.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:4.0.2.RELEASE:compile
[INFO] |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework:spring-orm:jar:4.0.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-jdbc:jar:4.0.2.RELEASE:compile
[INFO] |  \- org.springframework:spring-tx:jar:4.0.2.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:4.0.2.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:4.0.2.RELEASE:compile
[INFO] +- org.springframework.data:spring-data-jpa:jar:1.5.2.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:1.7.2.RELEASE:compile
[INFO] |  +- org.aspectj:aspectjrt:jar:1.7.4:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.6:compile
[INFO] |  \- org.slf4j:jcl-over-slf4j:jar:1.7.6:runtime
[INFO] +- commons-dbcp:commons-dbcp:jar:1.2.2:compile
[INFO] |  \- commons-pool:commons-pool:jar:1.3:compile
[INFO] \- log4j:log4j:jar:1.2.16:compile
package com.fedins.template.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.fedins.template.model.Account;

public interface AccountRespository extends JpaRepository<Account, String> {

}
(base class error)
The type org.springframework.data.domain.Sort cannot be resolved. It is indirectly referenced from required .class files 

(error on JpaRepository declaration)
The type org.springframework.data.repository.PagingAndSortingRepository cannot be resolved. It is indirectly referenced from required .class files
AnnotationConfigUtils.processCommonDefinitionAnnotations(…) is not public! Make sure you're using Spring 3.2.5 or better. The class was loaded from file:/C:/Program Files/STS/3.4/plugins/org.springframework.context_4.0.0.20130829-M3.jar.:org.springframework.context.annotation.AnnotationConfigUtils.processCommonDefinitionAnnotations(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)