Ioc和Aop的扩展

来源:互联网 发布:微信三级分销源码 编辑:程序博客网 时间:2024/05/27 20:51

三.Ioc和Aop使用扩展

DI注入(设置注入/构造注入/p命名注入)

1.构造注入

第一步(1)

 

 


(类二)


第二步:Xml文件



第三步:单测

 

 

2.集合注入

 类:



xml:





        array



3.(DI)注解 1.(小案例)

第一步: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 +                '}';    }}

原创粉丝点击