gpt4 book ai didi

java - Spring Boot EnableJpaRepositories 错误

转载 作者:行者123 更新时间:2023-11-30 03:10:07 24 4
gpt4 key购买 nike

我正在使用 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> {
}

配置文件

package com.springapp.app.config;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@Configuration
@EnableJpaRepositories("com.springapp.app.repository")
@EnableAutoConfiguration
@EntityScan("com.springapp.app.entity")
public class RepositoryConfig {
}

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>

最佳答案

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

关于java - Spring Boot EnableJpaRepositories 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33767097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com