Spring3.0 配置基本运行的jar包
Spring 新出了3.0.2版本,做为一个爱尝鲜的小学生,那当然要先试用下了,下载下来看了下,和从前的包的结构变化很大,从前要找sping.jar现在可好,没有这个东西,而且很多也不一样了,没办法,只能亲手测试下了,这里提供一个最小的运行所需jar文件的列表:
说明下这里用xml做为配置,使用Annotation,不用再加入另外的包就能使用,比以前的方便些许吧。
再放个程序的结构图吧,大家应该很容易理解的:
beans.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!-- services --><bean id="userDao" ref="userDao"/> <!-- additional collaborators and configuration for this bean go here --> </bean> <!-- more bean definitions for services go here --></beans>
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 {@Testpublic void testSave() {ApplicationContext acx = new ClassPathXmlApplicationContext("beans.xml");UserService us = (UserService)acx.getBean("service");User u = new User();us.save(u);}}
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 hierarchy2010-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 hierarchyUser add