当前位置:首页 > 开发 > 系统架构 > 架构 > 正文

Spring3: How to set up dependency jars for basic IoC function

发表于: 2013-04-17   作者:DavyJones2010   来源:转载   浏览次数:
摘要: 1. Import relevant jars for basic IoC purpose         1) Download spring-framework-3.2.2.RELEASE-dist.zip from http://www.springsource.org/download/community     &

1. Import relevant jars for basic IoC purpose

        1) Download spring-framework-3.2.2.RELEASE-dist.zip from http://www.springsource.org/download/community

        2) Open eclipse and set up user library

        3) Import relevant jars including:

            (1) spring-core-3.2.2.RELEASE.jar

            (2) spring-beans-3.2.2.RELEASE.jar

            (3) spring-expression-3.2.2.RELEASE.jar

            (4) spring-context-3.2.2.RELEASE.jar

        4) Download commons-logging-1.1.2-bin.zip from http://commons.apache.org/proper/commons-logging/download_logging.cgi

        5) Import relevant jars including:

            (1) commons-logging-1.1.2.jar

 

2. Create new java project and import user library created before. And import JUnit4 lib for unit test.

3. Start coding:

        1) beans.xml [In the root directory of src folder]

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

  <bean id="student" class="edu.xmu.domain.Student">
    <!-- collaborators and configuration for this bean go here -->
    <property name="id" value="1"/>
    <property name="name" value="Davy"/>
    <property name="age" value="23"/>
  </bean>
</beans>

         2) POJO

package edu.xmu.domain;

public class Student {
	private Integer id;
	private String name;
	private Integer age;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Integer getAge() {
		return age;
	}
	public void setAge(Integer age) {
		this.age = age;
	}
}

         3) Test case

package edu.xmu.domain;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class StudentTest
{

	@Test
	public void test()
	{
		ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");

		Student student = (Student) ac.getBean("student");

		System.out.println("Student info: ");
		System.out.println("ID: " + student.getId() + ", Name: "
				+ student.getName() + ", Age: " + student.getAge());
	}

}

Spring3: How to set up dependency jars for basic IoC function

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
This weekend, I deleted Windows Vista and installed Windows Server 2008 x64 on my home machin
cyper的实验结果: 按照这里的向导设置一次,以后只要ipad和mac都打开了wifi, 然后从mac中打开itune
Inversion of Control Containers and the Dependency Injection pattern Martin Fowler In the Jav
摘要 Martin Fowler的经典文章 + 透明的精彩翻译 + 1-2-3的UML插图(这个就不足挂齿了,呵呵)。 原
本文转载自 http://www.blogjava.net/rickhunter/articles/29015.html IoC与DI   首先想说说IoC(I
最近公司需要,项目中要用到Spring和Ibatis。趁着过年好好学习学习。Ibatis就如同Hibernate一样的持
撰文/Martin Fowler 编译/透明 Java 社群近来掀起了一阵轻量级容器的热潮,这些容器能够帮助开发者
撰文/Martin Fowler 编译/透明 Java 社群近来掀起了一阵轻量级容器的热潮,这些容器能够帮助开发者
转自http://blog.csdn.net/suncheng_hong/archive/2006/11/09/1375495.aspx Java社群近来掀起了一阵
2.1.1 IoC是什么 Ioc—Inversion of Control,即“控制反转”,不是什么技术,而是一种设计思想。在
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号