Spring_bean attributes and spring_bean attributes

Source: Internet
Author: User

[Convert] spring_bean attributes, spring_bean attributes

1. parent

Indicates the inherited parent class.

If there are many beans that inherit the same parent class

In the configuration file, you can omit the attributes injected by the parent class when implementing those beans.

The bean definition inherits the parent bean definition, which can overwrite some values of the parent bean or the values it needs.

In the configuration file, you can omit the attributes injected by the parent class when implementing those beans.

<Bean id = "carnetMgr" parent = "txProxyTemplate">

<Property name = "target">

<Bean class = "ecustoms. carnet. app. biz. CarnetMgr">

<Property name = "extensionHistoryDAO" ref = "extensionHistoryDAO"/>

<Property name = "stockTransactionDAO" ref = "stockTransactionDAO"/>

<Property name = "carnetDAO" ref = "carnetDAO"/>

</Bean>

</Property>

</Bean>

2. The list, set, map, and props elements are used to Set the attribute values of the type List, set, Map, and Propertis respectively. These are used to pass in set values for bean respectively.

An example of the corresponding spring configuration file is as follows:

<Bean id = "chinese" class = "Chinese">

<Property name = "friends">

<List>

<Value> Zhang San </value>

<Value> Li Si </value>

<Value> Wang Wu </value>

</List>

</Property>

<Property name = "score">

<Map>

<Entry key = "Mathematics">

<Value> 60 </value>

</Entry>

<Entry key = "English">

<Value> 70 </value>

</Entry>

<Entry key = "">

<Value> 80 </value>

</Entry>

<Entry key = "physical">

<Value> 90 </value>

</Entry>

<Entry key = "chemistry">

<Value> 95 </value>

</Entry>

</Map>

</Property>

<Property name = "basicInfo">

<Props>

<Prop key = "height"> 165 </prop>

<Prop key = "weight"> 45 kg </prop>

<Prop key = ""> bachelor degree </prop>

</Props>

</Property>

<Property name = "interest">

<Set>

<Value> singing </value>

<Value> dancing </value>

<Value> calligraphy </value>

</Set>

</Property>

</Bean>

The corresponding java code is as follows:

Public class Chinese implements People ...{

Private List friends = new ArrayList ();

Private Map score = new HashMap ();

Private Properties basicInfo = new Properties ();

Private Set interest = new HashSet ();

// Omitting the corresponding set Method

}

3. maxSize indicates the maximum value of data displayed on each page.

<Property name = "maxSize"> <value> 20 </value> </property>

The Bean element has many other attributes besides the preceding two attributes. Description:

<Bean

Id = "beanId" (1)

Name = "beanName" (2)

Class = "beanClass" (3)

Parent = "parentBean" (4)

Abstract = "true | false" (5)

Singleton = "true | false" (6)

Lazy-init = "true | false | default" (7)

ByName | byType | constructor | autodetect | default "(8)

Dependency-check = "none | objects | simple | all | default" (9)

Depends-on = "dependsOnBean" (10)

Init-method = "method" (11)

Destroy-method = "method" (12)

Factory-method = "method" (13)

Factory-bean = "bean"> (14)

</Bean>

4. id: the unique identification name of Bean. It must be a valid xml id, which is unique throughout the XML document.

5. name: used to create one or more aliases for the id. It can be any letter. Multiple aliases are separated by commas or spaces.

6. class: defines the fully qualified class name (package name + class name ). Only subclass beans do not need to define this attribute.

7. abstract ("false" by default): used to define whether the Bean is an abstract Bean. It indicates that the Bean will not be instantiated and is generally used for the parent class Bean, because the parent class Bean is mainly used for subclass Bean inheritance.

8. singleton ("true" by default): defines whether the Bean is Singleton (singleton ). If it is set to "true", only one instance of this Bean is maintained within the scope of BeanFactory. If it is set to "flase", the Bean will be Prototype (Prototype), and BeanFactory will create a new Bean instance for each Bean request.

9. lazy-init (the default value is "default"): used to define whether the Bean implements lazy initialization. If it is "true", it initializes all Singleton beans at BeanFactory startup. Otherwise, if it is "false", it will create a Singleton Bean only when the Bean request is made.

10. autowire (automatic assembly, default value: "default"): it defines the automatic loading method of Bean.

1. "no": automatic assembly is not used.

2. "byName": the Bean attribute name is used for automatic assembly.

3. "byType": automatically assemble the Bean type.

4. "constructor": similar to byType, but it is used to automatically assemble parameters of constructor.

5. "autodetect": The introspection of the Bean Class determines whether to use "constructor" or "byType ".

11. dependency-check (dependency check, default value: "default"): it is used to ensure that all dependencies described by Bean components through JavaBean are satisfied. It is particularly useful when used together with the automatic assembly function.

1. none: no dependency check is performed.

2. objects: Only checks the dependencies between objects.

3. simple: Only checks the original type and String type dependencies.

4. all: Check all types of dependencies. It includes the previous objects and simple.

12. depends-on: the object on which the Bean depends during initialization. this object will be created before Bean initialization.

13. init-method: used to define the Bean initialization method, which will be called after Bean assembly. It must be a non-parameter method.

14. destroy-method: used to define the Bean destruction method, which is called when BeanFactory is disabled. Similarly, it must be a non-parameter method. It can only be applied to singleton Bean.

15. factory-method: defines the factory method for creating the Bean object. It is used for the following "factory-bean", indicating that this Bean is created through the factory method. The "class" attribute is invalid.

16. factory-bean: defines the factory class for creating the Bean object. If "factory-bean" is used, the "class" attribute is invalid.

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.