我目前正在开发一个 POC,以将 Spring Boot 与 Spring Data JPA 结合使用。
我想使用 Spring Data JPA 从数据库中获取记录。
我收到以下错误
创建名称为“bookRepository”的 bean 时出错:设置 bean 属性“entityManager”时,无法创建 [org.springframework.orm.jpa.SharedEntityManagerCreator] 类型的内部 bean“(inner bean)”;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为“(inner bean)#2”的 bean 时出错:设置构造函数参数时无法解析对 bean“entityManagerFactory”的引用;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:未定义名为“entityManagerFactory”的 bean
这是我的配置类:
package com.boot.configration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@EnableAutoConfiguration
@ComponentScan
@EnableJpaRepositories
public class ApplicationStarter {
public static void main (String[] args) {
SpringApplication.run(ApplicationStarter.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
下面是我的存储库
package com.boot.configration;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface BookRepository extends JpaRepository<Book, String> {
public Iterable<Book> findBooksByAuthor(@Param("author") …
Run Code Online (Sandbox Code Playgroud)