spring03 使用注解的方式 配置bean和实现依赖的注入及整合Junite测试环境

本文介绍了如何使用注解的方式配置Spring Bean和实现依赖注入,详细讲解了在`applicationContext.xml`中配置`component-scan`以及在类中使用注解的方法。同时,内容还涉及了Spring与JUnit的测试环境整合。此外,文章简单阐述了AOP思想,将其比喻为对纵向逻辑的抽取,类似于Filter和Interceptor。
摘要由CSDN通过智能技术生成

 

一,使用注解配置Spring

1.在applicationContext.xml配置文件中配置

<context : component-scan base-package = "cn.itcast.beam."></context>

<!--指定扫描的那个包下的所有的类   -->
	<context:component-scan base-package="cn.itcast.beam.User"></context:component-scan>

2.再类中使用注解完成配置

package cn.itcast.beam;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

//本质上都是一样的,但是为了更加符合我们的思维习惯,javaee中三层架构的思想
//对象类型的注入
@Component("user&
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值