zoukankan      html  css  js  c++  java
  • Spring-bean的自动装配

      bean的自动装配:可以让一个bean对象自动的引用其他bean

      byType:按照类型进行装配。  缺点:如果在IOC容器中存在多个类型相同的bean的时候,会出现异常。

    <bean id="car1" class="com.spring.beans.Car" p:type="宝马"></bean>
    
    <bean id="person1" class="com.spring.beans.Person" autowire="byType"></bean>

       byName:要求bean的属性名称与引用的bean的id值保持一致

      <bean id="car1" class="com.spring.beans.Car" p:type="宝马"></bean>
        <bean id="car2" class="com.spring.beans.Car" p:type="奔驰"></bean>
    
    
        <bean id="car" class="com.spring.beans.Car" p:type="BMW"></bean>
    
        <bean id="person1" class="com.spring.beans.Person" autowire="byName"></bean>

      在bean配置文件里设置autowire属性进行自动装配将会装配Bean的所有属性,然而,若只希望装配个别属性是,autowire属性就不够灵活了。

      autowire属性要么根据类型自动装配,要么根据名称自动装配,不能两者皆有之。

      一般情况下,在实际的项目中很少使用自动装配功能,因为和自动装配功能所带来的好处比起来,明确清晰的装配文档更有说服力一点,

  • 相关阅读:
    poj3463 Sightseeing(最短路,次短路计数)
    poj3463 Sightseeing(读题很重要)
    poj3463 Sightseeing(读题很重要)
    hdu6181 Two Paths(次短路)
    hdu6181 Two Paths(次短路)
    Tyvj1293(新姿势:次短路)
    Tyvj1293(新姿势:次短路)
    10.bitset
    9.优先队列,priority_queue
    8.queue
  • 原文地址:https://www.cnblogs.com/gggyt/p/8668204.html
Copyright © 2011-2022 走看看