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"
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
什么情况? csdn再现?
呵呵, 楼主发能出来就已经不错了
不知道作者是图个方便还是什么原因,这样的包命名会误导别人。 而且你使用的是XML,并不是Annotation。
javaeye真JB差
这样的文章也。。。。。
看不出和spring2的区别
spring早就已经把那一大块分成小的包了啊!