Spring The goal is to create objects by default single
Sets the Bean range. By Bean Dollar Scope property
Scope Value Range:
Singleton: Single case
Proptotype: Non-singleton
Request: Create the Bean and call Request.setattribute ("Beanid", beanobj);
Session: Create the Bean and call Request.getsession (). SetAttribute ("Beanid", beanobj);
Globalsession: Global Session Distributed server
Test code
public class Initbeanapp {@Testpublic void Show () {ApplicationContext ac = new Classpathxmlapplicationcontext (" Applicatiocontext.xml "); Bean1 bean1 = (Bean1) ac.getbean ("bean2"); Bean1 bean2 = (Bean1) ac.getbean ("bean2"); Bean1 bean3 = (Bean1) ac.getbean ("Bean3"); Bean1 Bean4 = (Bean1) ac.getbean ("Bean3"); System.out.println (BEAN1); System.out.println (BEAN2); System.out.println (BEAN3); System.out.println (BEAN4);}}
Configuration Code
<!--bean scope--><!--scope: Used to set the scope default value of the Bean: Singleton Singleton--><bean id= "bean2" class= " Com.hao947.bean.Bean1 "scope=" singleton "></bean><!--the scope of the bean--><!--scope: For setting the bean range Default: Prototype--><bean id= "Bean3" class= "Com.hao947.bean.Bean1" scope= "prototype" ></bean>
Spring Bean Range Example