Spring in the automatic assembly

2011-05-08  来源:本站原创  分类:Java  人气:248 

Spring in the automatic assembly <br /> the form of automatic assembly byType, byName, no, construtor, autodetect and the default (beans tag did not, and bean tag are the property), a total of 6 kinds of assembly methods.

byType: in the container to find a property with the need for automatic assembly of the same type of Bean, if no match is found Bean, the property is not being assembled, if more than one match found when Bean (can not appear there are two classes of inheritance) will throw No unique bean of type of anomaly

Xml In the section of code :
<!--  Set the addressserviceimpl class  -->
        <bean>
                <property name="address">
                        <value> Hebei xingtai </value>
                </property>
        </bean>
        <!--  Set properties for the EMP class  -->
        <bean
                autowire="byType">
        </bean>

byName: the container needs to find and automatic assembly of the same property name Bean (or ID), if no match is found, Bean, the property has not been assembled on to.

Xml In the section of code :
        <!--  Set the addressserviceimpl class  -->
        <bean>
                <property name="address">
                        <value> Hebei xingtai </value>
                </property>
        </bean>
        <!--  Set properties for the EMP class  -->
        <bean
                autowire="byName">
        </bean>
        <!--  Set properties for the hour         -->
        <bean>
        </bean>
     Attention :byName And byType before use to have a default constructor , Class must ensure that the Bean can , Otherwise occur

constructor: to find the container and the need for automatic assembly Bean constructor parameters consistent with one or more of Bean. Bean or uncertain, such as construction method, the container will throw org.springframework.bean.unisatisfiedBependencyException exception. Injected through the constructor, the constructor arguments in the assembly in accordance with byType

Xml In the section of code :
<!--  Set the addressserviceimpl class  -->
        <bean>
                <property name="address">
                        <value> Hebei xingtai </value>
                </property>
        </bean>
        <!--  Set properties for the EMP class  -->
        <bean
                autowire="constructor">
        </bean>

no: no automatic assembly, the assembly must allow users to own, use the ref attribute assembly. Assembled in this way is the default mode

autodetect: test Autodetect automatic assembly methods, if not the default constructor is called seter method, seter method does not, then it can not operate out; if the default constructor method, first call the default constructor, if there seter method, then , then call seter method, if not, just call the default constructor

Xml In the section of code :
<!--  Set the addressserviceimpl class  -->
        <bean>
                <property name="address">
                        <value> Hebei xingtai </value>
                </property>
        </bean>
        <!--  Set properties for the EMP class  -->
        <bean
                autowire="autodetect">
        </bean>

default: This means only the bean tag has assembled this property, the equivalent of beans tag default-autowire = "no"

相关文章
  • Spring in the automatic assembly 2011-05-08

    Spring in the automatic assembly <br /> the form of automatic assembly byType, byName, no, construtor, autodetect and the default (beans tag did not, and bean tag are the property), a total of 6 kinds of assembly methods. byType: in the container to

  • Spring finishing 9 - automatic assembly (autowire) 2010-05-12

    Under the name of the automated assembly automated assembly according to the property name. This option will check the container and in accordance with the attribute name to find exactly the same bean, and its auto-assembly and properties. For exampl

  • Spring Bean automatic assembly 2010-10-17

    Spring BeanFactory provides automatic assembly of components dependent on the function of the object. Automatic assembly can be applied to each component, some components can be defined for the automatic assembly, while other components are not used.

  • Automatic assembly of byName 2011-04-24

    Automatic assembly of byName byName: automatic assembly according to the attribute name. This option will check the container and in accordance with the attribute name to find exactly the same bean, and automatic assembly with the property. For examp

  • Automatic assembly of byType 2011-04-24

    Automatic assembly of byType byType: If there is a container attribute with the same type specified bean, then the property will be automatic assembly. If there is more than the type of bean, it will throw an exception, and that way you can not use b

  • Automatic assembly (autowire) collaborators 2011-05-08

    Spring IoC container can be automatically assembled (autowire) collaborative relationship between the bean. Therefore, if possible, can automatically let Spring BeanFactory by checking the contents of the specified bean to back our collaborators (oth

  • Automatic assembly of the constructor 2011-04-24

    Automatic assembly of the constructor Constructor: the way with byType similar, in that it applies to constructor arguments. If not found in the container with the same constructor parameter type bean, it will throw an exception. The following exampl

  • Automatic assembly of the Autodetect 2011-04-24

    Automatic assembly of the Autodetect Autodetect: bean class through introspection mechanism (introspection) to determine ways to use constructor or byType automatic assembly. If you find that the default constructor, then use the byType way. The foll

  • AOP annotations in automatic assembly notice 2011-05-08

    AOP annotations in automatic assembly notice First, create an annotated class: Note: aop introduction package cn.csdn.util; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.AfterThrowing;

  • How to unit test the automatic assembly using Spring 2.5 functionality --- turn 2010-11-26

    Spring 2.5 ships with great support for integration testing through the classes in the org.springframework.test package. These classes allow you to dependency inject your test cases off of your existing Spring configuration, either by using your prod

  • Using struts + spring + hibernate web application assembly 2010-04-01

    This article will discuss how the combination of several well-known framework to achieve the purpose of loose coupling, how to build your framework, how to make you be consistent in all the application layer. Challenging is: the combination of these

  • Chapter constructor injection, automatic assembly, set into the 2010-05-02

    1: Inversion of Control (IOC): the object is an instance of the control has shifted in the past is our own new, now referred to instantiate the factory spring, if I use the object, the request directly to the spring this plant on it. In two ways: set

  • Spring order 5 - module assembly 2010-05-12

    How well the three modules switch? Profile <beans> <bean></bean> <!-- Will assemble to dao DaoCaller In dao property --> <bean> <property name="dao"> <ref local="dao"/> </property> </b

  • Kernel of Spring - the relationship between the management of three bean (auto assembly) 2010-10-06

    Spring BeanFactory provides similar automated assembly of components in the pico container dependent objects function. Automatic assembly can be applied to each component, some components can be defined for the automatic assembly, while other compone

  • Struts2 and Spring integration strategy in automated assembly 2011-10-14

    1 with the configuration of the automatic assembly [Org.apache.struts2.StrutsConstants class] Ø / / Spring should be how the assembly. Valid values: 'name', 'type', 'auto' and 'construtctor'. STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE Ø / / automatically s

  • Introduction to Spring 2 comments 2011-10-17

    A variety of annotation methods 1. @ Autowired comment (not recommended, recommend the use of @ Resource) @ Autowired can be member variables, methods, and constructors tagging, auto-assembly to complete the work. The annotation @ Autowired different

  • Xiang Jie struts2 in struts.properties 2010-03-29

    Struts 2 framework has two key configuration files: struts.xml and struts.properties One struts.xml document management applications is mainly responsible for the Action mapping, as well as the definition of Action contained in the Result. In additio

  • Struts2 properties file Xiangjie 2010-03-29

    struts.configuration This attribute specifies the Struts 2 configuration file loads the configuration file manager. The property's default value is org.apache.Struts2.config.DefaultConfiguration, which is Struts 2 default configuration file manager.

  • struts configuration Xiangjie 2010-03-29

    struts.configuration This attribute specifies the Struts 2 configuration file loads the configuration file manager. The property's default value is org.apache.Struts2.config.DefaultConfiguration, which is Struts 2 default configuration file manager.

  • Struts2 Study Notes 2 ----- Struts2 in constant (ie, default.properties file) Xiangjie 2010-03-29

    The struts2-core-2.1.8.1.jar/ora.apache.struts2/default.properties can see a lot of Struts2's constant, when you change some constants in the development contribute to the development. Sometimes programs also need to change inside the constant: So to