(4)下面是我写的接口和实现类
- package org.lxh.dao;
- public interface PersonDao {
- public abstract void sayHello();
- }
- package org.lxh.impl;
- import org.lxh.dao.PersonDao;
- public class PersonManger implements PersonDao {
- /* (non-Javadoc)
- * @see org.lxh.impl.PersonDao#sayHello()
- */
- public void sayHello(){
- System.out.println("Hello World");
- }
- }
(5)使用junit测试一下代码
- package org.lxh.test;
- import org.lxh.dao.PersonDao;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- public class Testunit {
- @org.junit.Test public void TestUse(){
- //初始化spring容器
- ApplicationContext context=new ClassPathXmlApplicationContext("beans.xml");
- //取得业务bean
- PersonDao dao=(PersonDao)context.getBean("personManager");
- dao.sayHello();
- }
- }
这里可以有多个spring配置文件,ClassPathXmlApplicationContext有多个构造函数,这里只是单个配置文件的情况
下面是运行结果

