zoukankan      html  css  js  c++  java
  • 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>
    

    五、测试结果截图:

  • 相关阅读:
    Linux 文件排序
    ubuntu18.04 美化桌面
    git clone 加速
    ubunutu下图像编辑器安装
    vue.js实战教程 https://www.jb51.net/Special/978.htm
    原生JS实现多条件筛选
    php结合js实现多条件组合查询
    js前端 多条件筛选查询
    JS 判断字符串是否全部为数字
    GET请求中URL的最大长度限制总结
  • 原文地址:https://www.cnblogs.com/northeastTycoon/p/9855843.html
Copyright © 2011-2022 走看看