---
title: "Spring3.0 配置基本运行的jar包"
author: "fantasy0707"
date: "2010-04-05T22:48:59Z"
tags: []
categories: ["企业架构"]
slug: "spring3-0-jar"
draft: false
lastmod: "2010-04-07T00:23:04Z"
id: 633765
url: "https://fantasy0707.iteye.com/blog/633765"
---

Spring 新出了3.0.2版本，做为一个爱尝鲜的小学生，那当然要先试用下了，下载下来看了下，和从前的包的结构变化很大，从前要找sping.jar现在可好，没有这个东西，而且很多也不一样了，没办法，只能亲手测试下了，这里提供一个最小的运行所需jar文件的列表：

![](http://dl.iteye.com/upload/attachment/229761/3988b858-74ce-3bd8-a6ed-fd160d5d4277.jpg)


说明下这里用xml做为配置，使用Annotation，不用再加入另外的包就能使用，比以前的方便些许吧。

再放个程序的结构图吧，大家应该很容易理解的：


![](http://dl.iteye.com/upload/attachment/229763/520a6b7e-ea70-30a3-87df-3ba2972edac2.jpg)

beans.xml配置：


```java


<?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">

  <!-- services -->
<bean id="userDao" 
        class="fantasy0707.spring.dao.impl.UserDAOImpl"></bean>
  <bean id="service" 
        class="fantasy0707.spring.service.UserService">
    <property name="dao" ref="userDao"/>
    <!-- additional collaborators and configuration for this bean go here -->
  </bean>

  <!-- more bean definitions for services go here -->

</beans>


```



单元测试代码：


```java


package fantasy0707.spring.service;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import fantasy0707.spring.model.User;

public class UserServiceTest {

	@Test
	public void testSave() {
		
		ApplicationContext acx = new ClassPathXmlApplicationContext("beans.xml");
		UserService us = (UserService)acx.getBean("service");
		
		User u = new User();
		us.save(u);
		
	}

}



```


运行结果：

```java


2010-4-5 22:50:41 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@f62373: startup date [mon apr 05 22:50:41 cst 2010]; root of context hierarchy
2010-4-5 22:50:42 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [beans.xml]
2010-4-5 22:50:43 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1431340: defining beans [userdao,service]; root of factory hierarchy
User add

```