论坛首页 Java企业应用论坛

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

浏览 9947 次
该帖已经被评为隐藏帖
作者 正文
   发表时间:2010-04-05   最后修改:2010-04-07
   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" 
        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>




单元测试代码:


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

}




运行结果:

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

  • 大小: 27.3 KB
  • 大小: 37.6 KB
   发表时间:2010-04-06  
这也能首页?
0 请登录后投票
   发表时间:2010-04-06  
spring早就已经把那一大块分成小的包了啊!
0 请登录后投票
   发表时间:2010-04-06  
看不出和spring2的区别
0 请登录后投票
   发表时间:2010-04-06  
不知道作者是图个方便还是什么原因,这样的包命名会误导别人。
而且你使用的是XML,并不是Annotation。
0 请登录后投票
   发表时间:2010-04-06  
呵呵,  楼主发能出来就已经不错了
0 请登录后投票
   发表时间:2010-04-06  
什么情况? csdn再现?
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics