zoukankan      html  css  js  c++  java
  • 在Spring中通过构造自动装配--constructor

    在Spring中,可以使用“通过构造自动装配”,实际上是按构造函数的参数类型自动装配。 这意味着,如果一个bean的数据类型与其他bean的构造器参数的数据类型是相同的,那么将自动装配。

    package auto_constructor;
    
    /**
     * Created by luozhitao on 2017/8/9.
     */
    public class student {
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        private  String name;
    }
    package auto_constructor;
    
    /**
     * Created by luozhitao on 2017/8/9.
     */
    public class school {
    
        public school(student st) {
            this.st=st;
        }
    
        public student getSt() {
            return st;
        }
    
        private student st;
    }
     <!--  构造方法注入   实际上是按构造函数的参数类型自动装配  -->
        <bean id="student" class="auto_constructor.student">
            <property name="name" value="猫儿"></property>
        </bean>
        <bean id="school" class="auto_constructor.school" autowire="constructor"></bean>

    在Spring,“通过自动检测自动装配”是指选,如果有默认构造函数(参数与任何数据类型)则安装构造函数注入,若没有构造函数则以“按类型自动装配”。

     <bean id="student" class="auto_constructor.student">
            <property name="name" value="猫儿"></property>
        </bean>
        <bean id="school" class="auto_constructor.school" autowire="autodetect"></bean>
  • 相关阅读:
    php命令注入
    mysql事物
    安装php环境
    移除服务器缓存实例
    show user profile synchronization tools
    manual start user profile import
    JSON is undefined. Infopath Form People Picker in SharePoint 2013
    asp.net web 应用站点支持域账户登录
    Load sharepoint envirement by powershell
    sharepoint 2016 download
  • 原文地址:https://www.cnblogs.com/luo-mao/p/7324436.html
Copyright © 2011-2022 走看看