spring-DI环境搭建


1.导入AOP的家暴

2.在配置文件中添加context约束条件

3.在配置文注册组件扫描器


例子:

package com.abc.di01;



import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


@Component("myschool")//表示当前类的对象由Spring管理


public class School {
   @Value("zs")
    private String sname;
   @Value("15")
    private String address;
    private int age;
public int getAge() {
return age;                                           

}



xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
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">
   


导入的jar包为框架\Spring\4.2.1\spring-framework-4.2.1.RELEASE-dist\spring-framework-4.2.1.RELEASE\docs\spring-framework-reference\html   xsd-configuration

aop jar包   spring-aop-4.2.1.RELEASE

你可能感兴趣的:(spring)