Spring Learning Note Bean configuration

Source: Internet
Author: User
Tags configuration settings naming convention

1. Named Bean

Each bean has one or more identifiers. These identifiers must be unique within the container in which they are loaded. A bean often has and has only one identifier, but if more than one name is required, additional aliases can be considered.

XML-based configuration source file, you can use the ID or the name attribute to specify the bean identifier, here is a question, if the name and ID of the inconsistency, how to handle the internal?

If you don't want to define another alias for them, you can specify the Name property, using a comma (,), semicolon (;), or a space. spring3.1 Previous id attribute is Xsd:id type, this is unique, after 3.1, the XML file is xsd:string This XML file is not verified, but spring needs it to be unique.

If a bean does not explicitly specify an ID or name, the container generates a unique name for the bean. However, if you want to use ref to reference, you must define a name.

Motivations for not supplying a name is related to using inner beans and autowiring collaborators.

How to understand this sentence?!!!!!!!!

Bean naming convention, like Java, with a lowercase character, hump

In the definition of a bean, you can give the bean more than one name, an ID, multiple names, name names and alias aliases are equivalent

2.

Within the container itself, these bean definitions is represented as beandefinition objects, which contain (among other Information) The following metadata:

A Package-qualified Class name:typically The actual implementation class of the bean being defined.
Bean Behavioral configuration elements, which state how the beans should behave in the container (scope, lifecycle callback s, and so forth).
References to and beans that is needed for the bean to do it work; These references is also called collaborators or dependencies.

What is the difference between cooperation and reliance?
Other-configuration settings to set-in the newly created object, for example, the number of connections to use in a bean t Hat manages a connection pool, or the size limit of the pool.
This is the metadata translates to a set of properties, the to the each bean definition.


Table 5.1. The bean definition

Property

Class instantiating Beans

Name naming beans

Scope Bean Scopes

Constructor Arguments Dependency Injection

Properties Dependency Injection

Autowiring Mode autowiring Collaborators

lazy-initialization Mode lazy-initialized Beans

Initialization method Initialization callbacks

Destruction Method Destruction Callbacks

In addition to bean definitions this contain information on what to create a specific bean, the ApplicationContext implementations also Permit the registration of existing objects that is created outside the container, by users. This is do by accessing the ApplicationContext ' s beanfactory via the method getBeanFactory() which returns the Beanfactory implemen Tation DefaultListableBeanFactory . DefaultListableBeanFactory supports this registration through the methods registerSingleton(..) and registerBeanDefinition(..) . However, typical applications work solely with beans defined through metadata bean definitions.

3.

Bean id= "Examplebean" class= "examples. Examplebean ">    <constructor-arg type=" int "value=" 7500000 "/>    <constructor-arg type=" Java.lang.String "Value="/></bean>
<bean id= "Examplebean" class= "examples. Examplebean ">    <constructor-arg index=" 0 "value=" 7500000 "/>    <constructor-arg index=" 1 "value=" "/></bean>

<bean id= "Examplebean" class= "examples. Examplebean ">
<constructor-arg name= "Years" value= "7500000"/>
<constructor-arg name= "Ultimateanswer" value= "/>"
</bean>

Fields omitted @ConstructorProperties ({"Years", "Ultimateanswer"}) public examplebean (int years, String Ultimateanswer) {this.years = years; this.ultimateanswer = Ultimateanswer;}

Spring Learning Note Bean configuration

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.