首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Spring3.0 配备基本运行的jar包

2012-11-03 
Spring3.0 配置基本运行的jar包Spring 新出了3.0.2版本,做为一个爱尝鲜的小学生,那当然要先试用下了,下载

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

这也能首页? 2 楼 Ethan29 2010-04-06   spring早就已经把那一大块分成小的包了啊! 3 楼 mgcnrx11 2010-04-06   看不出和spring2的区别 4 楼 rrsy23 2010-04-06   javaeye真JB差

这样的文章也。。。。。 5 楼 FreeWhere 2010-04-06   不知道作者是图个方便还是什么原因,这样的包命名会误导别人。
而且你使用的是XML,并不是Annotation。 6 楼 shuiguozheng 2010-04-06   呵呵,  楼主发能出来就已经不错了 7 楼 ivyshark 2010-04-06   什么情况? csdn再现?

热点排行