1.在jbuilder中,add libraries加入spring中的lib+dist中所有的jar.
2.按<spring开发指南>中的快速开始中的实例,写好,并写了一个test用来测试(不会用jnuit是个失败),但发现,ApplicationContext ctx=new FileSystemXmlApplicationContext("bean.xml");中ApplicationContext ,FileSystemXmlApplicationContext,无法识别。通过google,找到所属的类org.springframework.context.*和org.springframework.context.support.*.注,以后一定要熟悉各个类。
3。bean.xml一定要在工程的主目录下,即和jpx在一起,否则无法找到。
4。只是简单的copy了<spring开发指南>中的bean.xml,编译出错,说无法识别beans.后来加上<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">,编译通过。看来这种申明尤其指定dtd,还是很重要的,在dtd里应该定义了beans等关键字,不能偷懒省掉。
终于迈出第一步,虽然原理还不是很清楚,但还是高兴的一个下午。
附最后的编译结果过程,可以看出一点东西。
- Loading XML bean definitions from file [D:/jbproject/springtest/bean.xml]
- Bean factory for application context [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=26281671]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [TheAction]; Root of BeanFactory hierarchy
- 1 beans defined in ApplicationContext [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=26281671]
- No MessageSource found for context [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=26281671]: using empty default
- No ApplicationEventMulticaster found for context [org.springframework.context.support.FileSystemXmlApplicationContext;hashCode=26281671]: using default
- Refreshing listeners
- Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [TheAction]; Root of BeanFactory hierarchy]
- Creating shared instance of singleton bean 'TheAction'
hello rod johnson