您的位置:首页 > 编程语言 > Java开发

spring-DI环境搭建

2017-11-05 16:38 155 查看
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;                                           
}

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
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"> <!-- bean definitions here -->

   <context:component-scan base-package="com.abc.di01"></context:component-scan>

</beans>

导入的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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  eclipse spring aop