Java+spring+bean

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.