《spring---入门案例》

<?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">
		<bean id="personDao" class="com.fenghuo.dao.impl.PersonDaoBean"></bean>
</beans>
package com.fenghuo.dao.impl;

import com.fenghuo.dao.PersonDao;

public class PersonDaoBean implements PersonDao {
	public void add(){
		System.out.println("执行PersonDaoBeana的add()方法");
	}
}

package com.fenghuo.dao;

public interface PersonDao {

	public void add();

}

//测试类

package junit.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.fenghuo.dao.PersonDao;


public class SpringTest {
	 
	@Test public void instanceSpring(){
		ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
		PersonDao personDao = (PersonDao) ctx.getBean("personDao");
		
		personDao.add();
	}
}
《spring---入门案例》_第1张图片

你可能感兴趣的:(《spring---入门案例》)