Java Spring数据存储作为方法Bean
有没有办法在配置类中将Spring存储库创建为Bean?这样我就可以在一个类中拥有多个存储库,而不是为每个实体创建新的接口文件 我试图创建一个嵌套的@Repository接口,但无法自动连接 编辑: 如前所述Java Spring数据存储作为方法Bean,java,spring,spring-data,Java,Spring,Spring Data,有没有办法在配置类中将Spring存储库创建为Bean?这样我就可以在一个类中拥有多个存储库,而不是为每个实体创建新的接口文件 我试图创建一个嵌套的@Repository接口,但无法自动连接 编辑: 如前所述 @Repository public static interface CustomerRepository extends JpaRepository<Customer, Long> { List<Customer> findByLastNameStar
@Repository
public static interface CustomerRepository extends JpaRepository<Customer, Long> {
List<Customer> findByLastNameStartsWithIgnoreCase(String lastName);
}
它是SpringBootApplication类中的内部类。我不能使用@Bean注释,因为它会产生编译错误。结果是有一种方法被认为是repositories。请显示您尝试过的代码。当然,您不能使用@Bean方法。检测接口,Spring数据创建实现。您必须为所需的实体提供一个接口。无论是在单个文件中作为内部接口还是顶级接口,它们都必须存在。但这正是问题所在-它不适用于内部类接口为什么要将接口存储库定义为内部类?嗯。正如你们在文章中看到的,我不希望有10个空接口。我宁愿有一个类,我可以在其中声明这些接口。