现在的位置: 首页 > 综合 > 正文

spring2.5系列之———基本配置1

2018年02月13日 ⁄ 综合 ⁄ 共 1386字 ⁄ 字号 评论关闭

package junit.test;

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

import com.tiger.service.imple.PeopleService;

public class SpringTest
{

	@BeforeClass
	public static void setUpBeforeClass() throws Exception
	{
		
	}

	@Test
	public void test()
	{
		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		PeopleService peopleService = (PeopleService) ctx.getBean("peopleService");
		peopleService.save();
	}

}

package com.tiger.service.imple;

public interface PeopleService
{
	public void save();
}

package com.tiger.service.imple;

public class PeopleServiceBean implements PeopleService
{
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.tiger.service.imple.PeopleService#save()
	 */
	public void save()
	{
		System.out.println("我是save()方法");
	}
}

<?xml version="1.0" encoding="UTF-8"?>
<beans
	xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

	<bean id="peopleService" class=" com.tiger.service.imple.PeopleServiceBean"></bean>
</beans>

结果:

log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
我是save()方法

抱歉!评论已关闭.