One, the bean configuration file two kinds of loading mode:
1. Classpathxmlapplicationcontext: Only the configuration file under the Classpath can be loaded
2, Filesystemxmlapplicationcontext: Can load the disk any location of the configuration file
Two kinds of rules for bean creation:
1. Beanfactory: Provides a lazy loading idea to create a bean object. When to use the Bean object when to create
2. ApplicationContext: Provides an immediate loading idea to create a bean object. As soon as you finish parsing the configuration file, you create the object immediately.
Three, the bean three ways to create:
1, call the default parameterless constructor creation, this way to apply the most
By default, if there is no default parameterless constructor in the class, the creation fails and the exception is reported
2. Creating objects using methods in a static factory
You need to use the Factory-method property of the bean label to specify how the object is created in the static factory
3, using the method in the instance factory to create
Iv. Scope of the bean
Adjust the scope by configuration, using the scope property of the bean label
Value of the property:
Singleton: Singleton mode, default value
Prototype: Multiple cases mode
Request: The scope is a request, and the forwarding of the current request
Session: Scope is a conversation
Globalsession: The scope is a global session and is used primarily for clustering.
V. The Bean's life cycle
Two attributes involving the bean label
Init-method: Creating
Destroy-method: Destruction
Single Example:
Born: Container created, object is born
Alive: The container is in, the object has been
Death: Container destruction, object destruction
Multiple examples:
Born: Every use, create an object
Alive: As long as the object is in use, it always exists.
Death: When the object is not used for a long time and there is no other object reference, it is reclaimed by the Java garbage collector.
Java+spring+bean