Spring Ioc (this is my first example)
一、首先看下源码结构

二、HelloWord 类
package com.northeasttycoon.bean; /**
* 打印出 helloword 参数值
*
* @author tycoon jpa规范,hibernate是对它的一个实现
*/
public class HelloWord { // 普通方法
public void sayHello() { System.out.println("Hello Word!");
}
}
三、测试类,HelloWordTest源码介绍
/**
*
*/
package com.northeasttycoon.bean; // gradle 依赖关系插件
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* @author northEastTycoon
*
*/
public class HelloWordTest { @Test
public void test() { // Ioc 容器一种,使用依赖注入方式获得被调用者信息.无需关心被调用对象的变更信息.
// spring容器的一种,从spring中获得了相关对象.
// 容器提供生命周期及查找功能
BeanFactory context = new ClassPathXmlApplicationContext("applicationContext.xml");
// ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
HelloWord hello = (HelloWord) context.getBean("helloword");
hello.sayHello();
}
}
四、配置文件 applicationContext.xml代码
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean name="helloword" class="com.northeasttycoon.bean.HelloWord"/>
</beans>
五、测试结果截图:

Spring Ioc (this is my first example)的更多相关文章
- Spring IOC(二)容器初始化
本系列目录: Spring IOC(一)概览 Spring IOC(二)容器初始化 Spring IOC(三)依赖注入 Spring IOC(四)总结 目录 一.ApplicationContext接 ...
- Spring IOC(三)依赖注入
本系列目录: Spring IOC(一)概览 Spring IOC(二)容器初始化 Spring IOC(三)依赖注入 Spring IOC(四)总结 目录 1.AbstractBeanFactory ...
- Spring IOC(四)总结升华篇
本系列目录 Spring IOC(一)概览 Spring IOC(二)容器初始化 Spring IOC(三)依赖注入 Spring IOC(四)总结升华 =============正文分割线===== ...
- Spring IOC(一)概览
Spring ioc源码解析这一系列文章会比较枯燥,但是只要坚持下去,总会有收获,一回生二回熟,没有第一次,哪有下一次... 本系列目录: Spring IOC(一)概览 Spring IOC(二)容 ...
- Spring IOC(一)体系结构
Spring IOC(一)体系结构 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) BeanFactory 是Spring ...
- Spring IOC(二)beanName 别名管理
Spring IOC(二)beanName 别名管理 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 一.AliasReg ...
- Spring IOC(三)单例 bean 的注册管理
Spring IOC(三)单例 bean 的注册管理 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 在 Spring 中 ...
- Spring IOC(四)FactoryBean
Spring IOC(四)FactoryBean Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 一般情况下,Spring ...
- Spring IOC(五)依赖注入
Spring IOC(五)依赖注入 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 一.autowire 五种注入方式测试 ...
随机推荐
- 新人补钙系列教程之:拒绝CPU高占用
1.关于MovieClip和Sprite的鼠标事件,当不需要鼠标事件的时候将mouseEnabled和mouseChildren设为false. 不断的检测鼠标交互事件会消耗CPU,尤其是大量交互对象 ...
- python项目构建工具zc.buildout
转载:http://blog.csdn.net/u011630575/article/details/52940099 buildout简介 Buildout 是一个基于Python的构建工具, Bu ...
- 2017.3.31 spring mvc教程(四)全局的异常处理
学习的博客:http://elf8848.iteye.com/blog/875830/ 我项目中所用的版本:4.2.0.博客的时间比较早,11年的,学习的是Spring3 MVC.不知道版本上有没有变 ...
- ionic2项目创建回顾 及 react-native 报错处理
ionic2: 1.创建项目: ionic start MyIonic2Project tutorial --v2 (下载 tutorial 模板来初始化项目) ionic start MyIonic ...
- URAL 1984. Dummy Guy(数学啊)
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1984 1984. Dummy Guy Time limit: 0.5 second Me ...
- tail -f 不断刷新
查看log tail -f 会将其不断刷新显示
- MySql RESTRICT CASCADE SET NULL
主表,从表[MySql] //http://my.oschina.net/cart/blog/277624 空.RESTRICT.NO ACTION 删除:从表记录不存在时,主表才可以删除.删除从表, ...
- Oracle 日期总结
一.带星期格式 .SELECT to_char(to_date('2014-12-12','yyyy-mm-dd'),'MM-DD (DAY)') FROM DUAL .SELECT to_char( ...
- Spring MVC 学习笔记 spring mvc Schema-based configuration
Spring mvc 目前支持5个tag,分别是 mvc:annotation-driven,mvc:interceptors,mvc:view-controller, mvc:resources和m ...
- Atitit. 高级软件project师and 普通的差别 高级编程的门槛总结
Atitit. 高级软件project师and 普通的差别 高级编程的门槛总结 1. 完备的知识体系 2 2. 编程理论/原理的掌握 2 1.1. 掌握经常使用的概念(ORM,IOC.AOP,eve ...