标签:imp 命名 文件 one get sdn 注入 frame 技术分享
DI注入(设置注入/构造注入/p命名注入)
第一步(类1)
(类二)
第二步:Xml文件
第三步:单测
第一步:xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="cn.zhujiDI"/>
</beans>
第二步:实体类(Student类)
package cn.zhujiDI; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.annotation.Resource; /** * Student */ @Component("student") public class Student { @Value("阳光") private String name; @Value("18") private int age; public Car getCar() { return car2; } public void setCar(Car car) { this.car2 = car2; } @Resource() private Car car2; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "Student{" + "name=‘" + name + ‘\‘‘ + ", age=" + age + ", car=" + car2 + ‘}‘; } }
标签:imp 命名 文件 one get sdn 注入 frame 技术分享
原文地址:http://www.cnblogs.com/wangbenqing/p/7255329.html