【问题标题】:How Spring Container manage if 2 same bean have different id/name如果 2 个相同的 bean 具有不同的 id/name,Spring Container 如何管理
【发布时间】:2021-07-18 06:46:35
【问题描述】:

将在容器中创建多少对象。如果配置如下所示。

<bean id = "helloWorld" class = "com.tutorialspoint.HelloWorld"><br/>
  <property name = "message" value = "Hello World"/>
</bean>

<bean id = "helloWorld1" class = "com.tutorialspoint.HelloWorld">
  <property name = "message" value = "Hello World"/>
</bean>

【问题讨论】:

    标签: spring spring-boot spring-mvc spring-data-jpa


    【解决方案1】:

    spring容器中每个定义一个单例对象,如果你定义了N个bean,那么将创建该类的N个单例对象。

    它将在您的情况下创建两个实例,根据定义,Spring 容器为每个 bean 创建一个单例实例。

    【讨论】:

      猜你喜欢
      • 2016-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多