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 五种注入方式测试 ...
随机推荐
- 理解 VMWare的3种网络模型 z
在说到VMware的网络模型之前,先说一下VMware的几个虚拟设备: ■ VMnet0:这是VMware用于虚拟桥接网络下的虚拟交换机: ■ VMnet1:这是VMware用于虚拟Host-Only ...
- ylb:事务处理
ylbtech_sqlserver --1.定义三个变量分别保存你的姓名,年龄和身高,然后赋值并且输出 --DECLARE @name varchar(10) , @age int , @height ...
- log4j教程 9、HTMLLayout
如果想生成一个HTML格式的文件,日志信息,那么可以使用 org.apache.log4j.HTMLLayout 格式化日志信息. HTMLLayout类扩展抽象org.apache.log4j.La ...
- spring自动装配(No qualifying bean )
No qualifying bean of type [com.wfj.service.cms.main.ChannelMng] found for dependency: expected at l ...
- Android 百度地图 简单实现--- 美食搜索
Android 百度地图 简单实现--- 美食 依赖包: 加入 Android 百度依赖包: 1 key: <!-- 开发人员 key --> <meta-dat ...
- 关于ng-router嵌套使用和总结
那是某个下午的review代码的过程.js中有一段html,像是这样. var html = '<div>...此处还有很多html代码....</div>' 我的同事想我提出 ...
- Python魔法师
第一章:数据结构和算法 1.1 查找最大或者最小的n个元素 heapq 模块的两个函数 nlargest() nsmallest() import heapq nums = [1, 8, 2, 23 ...
- ACM-百度之星资格赛之Labyrinth——hdu4826
Labyrinth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【Java】Java_20 Scanner获取键盘输入
使用Scanner类可以很方便的获取用户的键盘输入,Scanner是一个基于正则表达式子的文本扫描器,他可以从文件.输入流.字符串中解析出基本类型值和字符串值. 例子示意: package com.o ...
- 【VBA】查看当前窗口的宽与高
打开的Excle如何使用VBA查看当前窗口的宽与高呢?代码如下: Sub 查看宽度与高度() Dim myWidth As Double Dim myHeigth As Double myWidth ...