spring 构造函数注入

1
2
3
4
5
6
7
8
9
10
11
12
package com.home;

public class {
private int age;
private String country;

User(int age, String country)
{
this.age=age;
this.country=country;
}
}
1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="user" class="com.home.User" >
<constructor-arg index="0" type="int" value="24"/>
<constructor-arg index="1" type="java.lang.String" value="China"/>
</bean>

</beans>