spring configuration file property tag ref, value, name difference

A difference property 'and the value of the ref

1.ref refers to an object that already exists

   value create a new object

2.value can assign values ​​and some simple types of objects

   ref bean can refer to other objects.

3. Use ref when, spring container will be validated in the references, verify the existence of the current xml referenced bean

     When using the value, spring vessel will start, when the bean is instantiated verify.

    -------------------------------------------------------------------------------------------------------------


Second, the difference between the property 'and the value of the name

 

<bean id="person" class="service.Person">

    <! - setAxe controller calls a method, the container is passed as a parameter axe bean ->

    <-! Name here is to determine the parameters of the Person class, ref name refers to bean bean configuration file ->

    <property name="axe" ref="axe">

    </property>

</bean>


Here's name and ref although the same name, but the name refers to the argument Person class, the Person class has an object type called a Axe axe, while the ref is the current xml file named axe this bean, treat it as a as a parameter passed into the Person of.

Not a direct quote . To be studied.

 

Guess you like

Origin www.cnblogs.com/weixupeng/p/11453416.html