第一种
<bean id="date" class="java.util.Date"></bean>
<bean id="tianfen" class="com.qfedu.ioc.bean.Tianfen" autowire="byType" >
<property name="title" value="P8"></property>
<property name="date" ref="date">
</property>
</bean>
第二种
<bean id="tianfen" class="com.qfedu.ioc.bean.Tianfen" autowire="byType" >
<property name="title" value="P8"></property>
<property name="date" >
<bean class="java.util.Date"></bean>
</property>
</bean>
自动装配
<bean id="rvrt" class="com.qfedu.ioc.bean.Clazz">
<property name="number" value="3"></property>
</bean>
<bean id="clazzyfyufuf" class="com.qfedu.ioc.bean.Clazz">
<property name="number" value="6"></property>
</bean>
<bean id="student" class="com.qfedu.ioc.bean.Student" autowire="byName" >
<property name="stuNum" value="1"/>
<property name="stuName" value="ygl"/>
<property name="stuAge" value="21"/>
<property name="enterenceTime" ref="date"></property>
</bean>
public class Test {
public static void main(String[] args) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Object tianfen = context.getBean("student");
System.out.println(tianfen);
}
}
spring注解配置
|