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 五种注入方式测试 ...
随机推荐
- etcd:从应用场景到实现原理的全方位解读
随着CoreOS和Kubernetes等项目在开源社区日益火热,它们项目中都用到的etcd组件作为一个高可用强一致性的服务发现存储仓库,渐 渐为开发人员所关注.在云计算时代,如何让服务快速透明地接入到 ...
- 使用Intent调用内置应用程序
布局代码如下: <?xml version="1.0" encoding="utf-8" ?> <LinearLayout xmlns:and ...
- samba 服务实现在windows共享文件
1. 什么是samba Samba服务类似于windows上的共享功能,可以实现在Linux上共享文件,windows上访问,当然在Linux上也可以访问到. 是一种在局域网上共享文件和打印机的一种通 ...
- java GC optimization, G1GC
引用 http://www.avricot.com/blog/?post/2010/05/03/Get-started-with-java-JVM-memory-(heap%2C-stack%2 ...
- 最简单简洁高效的Json数据解析
一.无图无真相 二.主要代码 1.导入jar包 拷贝fastjson.jar包到projectlibs包下 2.封装工具类JsonUtil.java package com.example.parse ...
- 在 Linux 系统下使用 PhotoRec & TestDisk 工具来恢复文件
当你在系统中有意或无意地使用 shift + delete 组合键.删除选项,或是清空回收站的方式来删除一个文件时,该文件的内容并没有从硬盘(或是其它存储设备)上直接销毁. 它仅仅是从系统的目录结构中 ...
- handlebars.js基础学习笔记
最近在帮学校做个课程网站,就有人推荐用jquery+ajax+handlebars做网站前端,刚接触发现挺高大上的,于是就把一些基础学习笔记记录下来啦. 1.引用文件: jquery.js文件下载:h ...
- 【SpringMVC学习11】SpringMVC中的拦截器
Springmvc的处理器拦截器类似于Servlet 开发中的过滤器Filter,用于对处理器进行预处理和后处理.本文主要总结一下springmvc中拦截器是如何定义的,以及测试拦截器的执行情况和使用 ...
- Docker iptables failed: iptables -t nat -A DOCKER -p tcp
Dokcer网络问题 因为操作或修该过iptables导致docker容器出现如下错误: [root@mysqlserver ~]# docker restart cvnavi-centos-tomc ...
- .Net 异步调用
.NET异步编程之新利器——Task与Await.Async 一. FrameWork 4.0之前的线程世界 在.NET FrameWork 4.0之前,如果我们使用线程.一般有以下几种方 ...