阅读背景:

如何在spring中通过xml文件将值传递给多个参数化构造函数?

来源:互联网 
        I have three files
        1) Test.java (in which i have created two parameterized constructor)
        2) spring.xml (xml file)
        3) Client.java(in which i have created main method)

        1)Test.java

        public class Test {
        private String name,email;
        private int age;

            public Test(String name,int age)
            {
                this.name=name;
                this.age=age;
            }
            public Test(String name)
            {
                this.name=name;
            }
            public void display()
            {
                System.out.println("First Constructor "+name+" "+age);
                System.out.println("Second Constructor "+name);

            }
        }



    2) spring.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
    "https://www.springframework.org/dtd/spring-beans-2.0.dtd">

    <beans>
    <bean id="testObj" class="Test" >

    <constructor-arg value="name"  index="0"/>

    <constructor-arg value="123"  index="1"/>

    <constructor-arg value="name"/>

    </bean>
    </beans>

3) Client.java

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
        I have three files
        1) Test.java



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: