烤包 spring.jar commons-logging.jar
写配置文件 application.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-2.5.xsd" ><!--主要针对这一行-->
<!--
最后一行是在有网的情况下,这样就行了,但是在没有网 的情况下 怎么办了
1:window--myeclipse--file and editors --xm--xml catalog
2:选择user specified entries 点击add 点击file system 选择 spring-beans-2.5.xsd 这个文件
3:将Key Type选为 Schema Location
4:把/spring-beans-2.5.xsd 加到key的后面 点击ok
或者把spring-beans-2.5.xsd 这个文件拷到src下面 把那一行改成文件名就行
->
</bean>
实例化spring容器
一:在类路径下寻找配置文件来实例化容器 (开发更好)
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"beans.xml","beans2.xml"});
二是:在文件系统路径下寻找配置文件来实例化容器
ApplicationContext ctx=new FileSystemXmlApplicationContext(new String[]{"d:\\beads.xml"});//路径不是很好
检验环境配置的正确性
利用在junit.test包下面写入SpringTest.java,里面的instanceSpring()实例化spring容器来检验
再写业务bean(com.service.impl.PersonServiceBean),在里面的方法(save())抽出接口(PersonService.java)并放在 com.service下面,
将业务bean交给spring管理容器<bean id="personService" class="com.service.impl.PersonServiceBean"></bean>
在Test类中,接口指向实现这个接口的对象实例,调用这个对 象中的方法