bean scope
Scope can be used to specify the scope of the bean
-singleton The default value. When the IOC container is created, it will create an instance of the bean, and it is a singleton, and the same one is obtained every time
-prototype Prototype. When the IOC container is created, the bean is no longer instantiated, and the bean is instantiated every time the getBean method is called
-request instantiates a bean per request
-session share a bean in a session
//创建IOC容器对象
ApplicationContext ioc=new ClassPathXmlApplicationContext("beans.xml");
@Test
void testBook(){
Book book=(Book)ioc.getBean("book");
}
<bean id="book" class="com.diko.spring.beans.Book" scope="singleton">
<property name="id" value="8"></property>
</bean>