簡體   English   中英

STS + Spring Data JPA + Hibernate存儲庫XML配置問題

[英]STS + Spring Data JPA + Hibernate repositories XML config issue

我在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版本(core / tx / beans / test / aop / context / expression):4.0.2.RELEASE

Spring Data JPA版本:1.5.0.RELEASE

Hibernate版本(不確定為什么這很重要):4.2.1.Final

POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.spring</groupId>
<artifactId>test-spring-transactional</artifactId>
<version>1.0.1</version>
<packaging>jar</packaging>
<name>Spring Transactional Test Project</name>
<url>http://www.imatestapp.com</url>
<description>This project is a minimal jar utility with Spring configuration for Hibernate set up.</description>
<properties>
    <maven.test.failure.ignore>true</maven.test.failure.ignore>
    <spring.framework.version>4.0.2.RELEASE</spring.framework.version>
    <hibernate.version>4.2.1.Final</hibernate.version>
    <spring.framework.data.version>1.5.0.RELEASE</spring.framework.data.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.framework.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring.framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.framework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>${spring.framework.data.version}</version>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

依賴樹(更新到Spring Data 1.5.2,仍然是同一個問題):

[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

**根據以下回復更新以更新到Spring Data JPA 1.5.2 **

更新到JPA 1.5.2“可能”已經解決了上述問題(因為XML不再抱怨引用私有方法),但仍然存在參考問題。 現在我的存儲庫找不到JpaRepository引用的“PagingAndSorting”存儲庫(盡管它可以找到JpaRepository本身):

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> {

}

此界面中有2個錯誤:

(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

**最終更新**上述問題是本地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的一個問題: https//jira.spring.io/i#browse/DATAJPA-490我將升級到STS 3.5以查看它是否解決了這個問題。

這肯定是由於您的類路徑未正確設置。 我們嘗試使用的相關方法是Spring Context中的AnnotationConfigUtils.processCommonDefinitionAnnotations(AnnotatedBeanDefinition abd) 此方法已在3.2.5和4.0.0版本中公開。 因此,如果您按照描述設置了類路徑,則不會發生異常。

我建議升級到更新版本的Spring Data JPA(1.5.2.RELEASE是截至本文撰寫時的最新版本),因為我們引入了一個專門檢查方法的存在和公開,以提供一個比一個更好的例外你現在得到了。

它可能是其他一些庫在舊版本中引入Spring JAR,但默認情況下,Spring Data項目肯定會引入與庫兼容的Spring版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM