gpt4 book ai didi

java - Spring Boot 具有更多上下文

转载 作者:行者123 更新时间:2023-12-02 13:16:30 25 4
gpt4 key购买 nike

我有一个 Spring Boot,其主类带有 @SpringBootApplication (因此它具有隐含标签 @EnableAutoConfiguration@ComponentScan@Configuration)。

如果我使用注释 @Configuration@ComponentScan 创建另一个类,会发生什么?我要创建另一个容器来装 bean 吗?这样 bean 就重复了?创建更多 @Configuration 类是一个好方法吗? @Configuration 创建一个 bean 容器?如果是,两个容器共享 bean?

我需要理解这些问题。

最佳答案

What happens if i create another class with annotation @Configuration and @Component Scan?

没关系,很正常..

I create another container of beans ? In this way the beans are Duplicates ?

如果您创建两个相同类型的bean,则在应用程序启动时会出现错误。您需要将其中一个声明为@Primary

关于java - Spring Boot 具有更多上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43743750/

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