Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果两个相同的bean具有不同的id/名称,Spring容器如何管理_Spring_Spring Boot_Spring Mvc_Spring Data Jpa - Fatal编程技术网

如果两个相同的bean具有不同的id/名称,Spring容器如何管理

如果两个相同的bean具有不同的id/名称,Spring容器如何管理,spring,spring-boot,spring-mvc,spring-data-jpa,Spring,Spring Boot,Spring Mvc,Spring Data Jpa,将在容器中创建多少个对象。如果配置如下所示。 <bean id = "helloWorld" class = "com.tutorialspoint.HelloWorld"><br/> <property name = "message" value = "Hello World"/> </bean> <bean id = "helloWorld1

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

<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容器中,每个定义一个单例对象,如果您定义了N个bean,那么将创建该类的N个单例对象

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