`
DavyJones2010
  • 浏览: 147792 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

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

阅读更多

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());
	}

}
分享到:
评论

相关推荐

    ASP.NET Core 1.1 For Beginners: How to Build a MVC Website

    ASP.NET Core 1.1 For Beginners: How to Build a MVC Website by Jonas Fagerberg English | 19 May 2017 | ASIN: B071VX7KN4 | 411 Pages | PDF | 6.66 MB Want to learn how to build ASP.NET Core 1.1 MVC Web ...

    Pro Spring 3

    How to build transaction engines for your enterprise application and take advantage of other middle-tier features in Spring How to build Spring-based web applications using Spring MVC and more How to ...

    Deep Semantic Analysis: from Dependency Tree to Dependency Graph

    Deep Semantic Analysis: from Dependency Tree to Dependency Graph

    Mastering Spring 5: 2nd Edition

    You'll learn about the standard dependency injection specification for Java contexts and CDI and how the Spring Framework supports it. You'll gain an understanding of how application architectures ...

    configuration

    configuration.js是一个好用的东西。

    Apache Maven Dependency Management

    Chapter 3: Dependency Designation (advanced) Chapter 4: Migration of Dependencies to Apache Maven Chapter 5: Tools within Your IDE Chapter 6: Release and Distribute Appendix: Useful Public ...

    springioc和spring aop

    控制反转(Inversion of Control,缩写为IoC),是面向对象编程中的一种设计原则,可以用来减低计算机代码之间的耦合度。其中最常见的方式叫做依赖注入(Dependency Injection,简称DI),还有一种方式叫“依赖查找...

    Spring_IoC入门笔记.md

    依赖注入:Dependency Injection IOC的作用:降低程序间的偶合(依赖关系) 依赖关系的管理:以后都交给spring来维护 在当前类需要用到其他类的对象时,由spring为我们提供,我们只需在配置文件中说明 依赖关系...

    IoC 容器和Dependency Injection 模式

    IoC 容器和Dependency Injection 模式

    Pro Spring 5 An In-Depth Guide -Apress(2017)

    • Use Spring Boot to an advanced level to get any kind of Spring application up and running in no time • Use Java 9 features in Spring applications Because the Java 9 release date kept being ...

    第一个spring IOC例子(maven)

    如果发现出现applicationContext could not resolve to a type, 可能是依赖没下载完或者下载失败,或者jar包出现问题,解决方法删除这个jar包,然后重新下载。在Eclipse中选中项目右键展开run as,然后选中maven ...

    Learning Spring 5.0

    Beginning with an introduction to Spring and setting up the environment, the book will teach you in detail about the Bean life cycle and help you discover the power of wiring for dependency injection....

    Dependency Walker for Win32 (x86)

    从C++中分离出来的,用来检测EXE和DLL的文件关联的小工具,很实用

    Gradle.Dependency.Management.1784392782

    Learn how to use Gradle's powerful dependency management through extensive code samples, and discover how to define, customize, and deploy dependencies About This Book Be in total control of your ...

    SpringMVC3.1.2 入门级HelloWorld源码

    (maven查看的dependency) [INFO] SpringStart:SpringStart:war:V1.0.0 [INFO] +- log4j:log4j:jar:1.2.17:compile [INFO] +- org.apache.openejb:javaee-api:jar:5.0-1:provided [INFO] +- javax.faces:jsf-api:jar:...

    spring 最新框架jar

    The framework also serves as the foundation for [Spring Integration][], [Spring Batch][] and the rest of the Spring [family of projects][]. Browse the repositories under the [Spring organization][] on...

    Google Guice: Agile Lightweight Dependency Injection Framework

    This book is for professional Java developers who are interested in dependency injection, modern Java coding practices and who want to tackle complexity with a simple, powerful and high-quality ...

    Gus add noise to dependency matrix function_NOISE_matlabfunction

    for simulate random walk model on graph function can using to add Gaussian noise to dependency matrix

    Java 9 Dependency Injection.7z

    1: WHY DEPENDENCY INJECTION?...3: DEPENDENCY INJECTION WITH SPRING 4: DEPENDENCY INJECTION WITH GOOGLE GUICE 5: SCOPES 6: ASPECT-ORIENTED PROGRAMMING AND INTERCEPTORS 7: IOC PATTERNS AND BEST PRACTICES

Global site tag (gtag.js) - Google Analytics