Spring3.0学习笔记

Spring3.0不但需要Spring的标准jar包,还有些与2.5增加了的一些jar包:aspectjweaver.jar,aspectjrt.jar,log4j-1.2.16.jar,commons-logging-1.1.1.jar,aspectj-1.6.10.jar,asm.jar,cglib-2.1.3.jar,aopalliance.jar,aopalliance-alpha1.jar

package com.fire.dao;

public interface UserDao {


}

package com.fire.dao.impl;

import com.fire.dao.UserDao;

public class UserDaoImpl implements UserDao{

	public UserDaoImpl() {
		System.out.println("***********Create  ****UserDaoImpl()*************");
	}

}

package com.fire.service;

import com.fire.dao.UserDao;


public class UserDaoService {
	
	public UserDaoService() {
		System.out.println("Create ********UserDaoService()**********");
	}

	private UserDao userDAO;

	public UserDao getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(UserDao userDAO) {
		this.userDAO = userDAO;
	}

	



}

<?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="userDao" class="com.fire.dao.impl.UserDaoImpl" />
	
	<bean id="userService" class="com.fire.service.UserDaoService" >
		<property name="userDAO" ref="userDao"/>
	</bean>
	
</beans>

package com.fire.test;



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

import com.fire.service.UserDaoService;

public class UserDaoImplTest {
	
	@Test
	public void testUserDaoService(){
		
		ApplicationContext  app = new ClassPathXmlApplicationContext("beans.xml");
		UserDaoService user = (UserDaoService) app.getBean("userService");
		
		
	}

}

你可能感兴趣的:(java,DAO,spring,log4j,xml)