1 准备工作

1.导包 4+2+spring-aop【新版本需要导入 spring-aop 包】

2.为主配置文件引入新的命名空间(约束) 【context】

3.开启使用注解代理配置文件

4.在类中使用注解完成配置

2 将对象注册到容器

3 修改对象的作用范围

4 值类型注入

5 引用类型注入

6 初始化|销毁方法

7 spring 整合 junit 测试

package www.test.b_junit;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import www.test.bean.User; //帮我们创建容器
@RunWith(SpringJUnit4ClassRunner.class)
//指定创建容器的时候使用哪个配置文件
@ContextConfiguration("classpath:applicationContext.xml")
public class Demo { //将名为user的对象注入到u变量中
@Resource(name="user")
private User u; @Test
public void fun1(){
System.out.println(u);
}
}

02-使用注解配置spring的更多相关文章

  1. JAVAEE——spring02:使用注解配置spring、sts插件、junit整合测试和aop演示

    一.使用注解配置spring 1.步骤 1.1 导包4+2+spring-aop 1.2 为主配置文件引入新的命名空间(约束) 1.3 开启使用注解代替配置文件 1.4 在类中使用注解完成配置 2.将 ...

  2. 注解配置spring

    1.为什么使用注解配置Spring基于注解配置的方式也已经逐渐代替xml.这个是不可逆的潮流,所以我们必须要掌握使用注解的方式配置Spring 总结:(1)使用注解配置Spring,注解的作用就是用于 ...

  3. 使用注解配置Spring

    使用注解配置Spring 1.为主配置文件引入新的命名空间(约束) 2.开启使用注解代理配置文件 3.在类中使用注解完成配置 将对象注册到容器 修改对象的作用范围 值类型注入 引用类型注入 注意: 初 ...

  4. Spring系列之新注解配置+Spring集成junit+注解注入

    Spring系列之注解配置 Spring是轻代码而重配置的框架,配置比较繁重,影响开发效率,所以注解开发是一种趋势,注解代替xml配置文件可以简化配置,提高开发效率 你本来要写一段很长的代码来构造一个 ...

  5. Spring学习笔记(三)—— 使用注解配置spring

    一.使用步骤 1.1 导包 1.2 为主配置文件引入新的命名空间(约束) 在applicationContext.xml中引入context约束 1.3 编写相关的类 public class Use ...

  6. 基于注解配置spring

    1 对 bean 的标注基于注解方式有3个注解 @Component @Repository 对DAO类进行标注 @Service 对Service类进行标注 @Controller  对Contro ...

  7. 使用注解配置Spring框架自动代理通知

    话不多说上代码 项目架构图及Lib包如下: 第二步创建业务类接口 package cn.happy.day01.entity; /** * 1.业务接口 * @author Happy * */ pu ...

  8. 基于注解的Spring AOP的配置和使用

    摘要: 基于注解的Spring AOP的配置和使用 AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不 ...

  9. 基于注解的Spring AOP的配置和使用--转载

    AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...

随机推荐

  1. [转]xe6 android 使用距离传感器(Proximiry)

    The first step it's a run sample from RAD Studio that named SensorInfo on your device. On the tab Bi ...

  2. OkHttp3的简单使用(一)

    一.导入 1)gradle方式: compile 'com.squareup.okhttp3:okhttp:3.8.0'(okhttp 最新版) compile 'com.squareup.okio: ...

  3. HTML4.0 需要掌握的主要内容

    常用标签: <html></html> 创建一个HTML文档 <head></head> 设置文档标题和其它在网页中不显示的信息 <title&g ...

  4. mysql 字符串的截取与连接

    mysql 字符串的截取   left() .right() .  substring()[ mid() .substr() 等价于substring() ] .substring_index() l ...

  5. 多线程《八》线程queue

    一 线程queue queue is especially useful in threaded programming when information must be exchanged safe ...

  6. django使用auth模块进行身份认证

    https://docs.djangoproject.com/zh-hans/2.0/topics/auth/default/#authentication-in-web-requests djang ...

  7. Linux简单部署svn服务

    最近需要练习一下svn的命令行使用方法,以便编写自动化部署的脚本,但是不敢用正式的svn库进行练习,所以自己部署了一个svn服务,用来练习 1.安装svn server 我用的是ubuntu $apt ...

  8. leecode刷题(6)-- 两个数组的交集II

    leecode刷题(6)-- 两个数组的交集II 两个数组的交集II 描述: 给定两个数组,编写一个函数来计算它们的交集. 示例: 输入: nums1 = [1,2,2,1], nums2 = [2, ...

  9. VS2010 UAC执行级别修改

    配置属性 -> 链接器 -> 清单文件 -> UAC执行级别 改为 requireAdministrator 这个级别即可.

  10. query flot 直方图上显示对应的y值

    方法1:使用在图上加 相对定位的 div 提示对应的直方图数量. 具体实现:获取直方图上所有的点,得到y值和对应的坐标位置,插入相对div 主要js代码:plot 为对应的图对象 //初始化柱状图数据 ...