gpt4 book ai didi

spring - 何时创建存储库接口(interface) (jpaRepository) bean?

转载 作者:行者123 更新时间:2023-12-05 05:22:53 26 4
gpt4 key购买 nike

即使我的接口(interface) MonRepo(它扩展了 JpaRepository)没有使用任何告诉 spring 为这个类(例如服务、 Controller 、组件等)创建 bean 的注解进行注解。此类的 bean 是如何创建的。我确定创建了一个 bean,因为我在另一个类中 Autowiring 了 monRepo,并且它工作得很好。

MonRepo

public interface MonRepo extends MongoRepository<Mon, Long> {
public List<Mon> findAllBymId(@Param("mId") Long mId);
}

Autowiring monRepo 的类

@Component("iRuleEngine")
public class RuleEngine implements IRuleEngine {

@Autowired
private MonRepo monRepo;
.
.
.
}

除了我的类(class),我没有在任何地方使用过 enableJpaRepository 注释。MonRepo 确实在我的组件扫描范围内。

最佳答案

您似乎已经配置了包含 MonRepo 的包作为带有 @EnableJpaRepositories 注释或相应 XML 配置的存储库包。

documentation 中所述:

By default the infrastructure picks up every interface extending the persistence technology-specific Repository subinterface located under the configured base package and creates a bean instance for it.

关于spring - 何时创建存储库接口(interface) (jpaRepository) bean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39345457/

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