Java Spring Boot EnableJpaRepositories错误

Java Spring Boot EnableJpaRepositories错误,java,hibernate,spring-boot,Java,Hibernate,Spring Boot,我正在使用Spring boot和hibernate构建应用程序,在添加存储库后,我遇到这样的错误: [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.7.RELEASE:run (default-cli) on project app: An exception occured while running. null: InvocationTargetException: F

我正在使用Spring boot和hibernate构建应用程序,在添加存储库后,我遇到这样的错误:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.7.RELEASE:run (default-cli) on project app: An exception occured while running. null: InvocationTargetException: Failed to read candidate component class: file [/home/scabbard/projects/app/app-back-end/target/classes/com/springapp/app/config/RepositoryConfig.class]; nested exception is java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.springframework.data.jpa.repository.config.EnableJpaRepositories.repositoryBaseClass() -> [Help 1]
看起来问题出在EnableJpaRepositories上,但无法找出原因

以下是其他文件:

存储库文件

package com.springapp.app.repository;

import com.springapp.app.entity.PressEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface PressRepository extends JpaRepository<PressEntity, Long> {
}
pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.springapp.app</groupId>
    <artifactId>app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>App</name>

    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.7.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.2.7.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.9.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.4-1205-jdbc42</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.0.2.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency>


    </dependencies>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.2.7.RELEASE</version>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>

</project>

4.0.0
com.springapp.app
应用程序
1.0-快照
罐子
应用程序
org.springframework.boot
spring启动程序父级
1.2.7.发布
org.springframework.boot
SpringBootStarterWeb
1.2.7.发布
org.springframework.data
spring数据jpa
1.9.0.1发布
org.postgresql
postgresql
9.4-1205-jdbc42
org.hibernate
休眠实体管理器
5.0.2.2最终版本
org.hibernate
休眠注释
3.5.6-最终版本
1.8
org.springframework.boot
springbootmaven插件
1.2.7.发布
春假
https://repo.spring.io/libs-release
春假
https://repo.spring.io/libs-release

在将hibernate依赖项和“spring data jpa”更改为“spring boot starter data jpa”并添加了“application.properties”之后,它解决了我的问题。

首先,您应该删除依赖项hibernate注释。这不再是必需的,并且可能会导致依赖关系冲突。第二,我建议使用依赖项“spring boot starter data jpa”而不是“spring data jpa”。你能解释一下为什么不需要Hibernate依赖项吗?因为我猜“spring boot starter data jpa”已经有了,但不明白为什么?不需要Hibernate注释。正如您所看到的,hibernate注释的版本是3.5.6,因此它非常旧,新的hibernate版本不再需要它。“spring boot starter data jpa”将引入Hibernate作为默认jpa提供程序,因此您可以选择删除Hibernate entitymanager依赖项或将其保留在POM中,这无关紧要。感谢您的解释,它确实帮助我解决了问题。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.springapp.app</groupId>
    <artifactId>app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>App</name>

    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.7.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.2.7.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.9.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.4-1205-jdbc42</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.0.2.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency>


    </dependencies>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.2.7.RELEASE</version>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>

</project>