spring入门演示(一)

最近没事,研究spring底层结构,工作一年多一直是小兵,都是经理搭框架,我们实现代码,一年多了没什么进展,除了在页面上有一些花样外,其他么学到什么,闲话少说开始入正题:
1.新建spring工程,导入需要的包,spring.jar,commons-logging.jar,或者用myeclise添加spring包
2.新建一个接口IuserDao
/**
*
*/
package com.youxigu;

import java.util.List;

/**
* @author <a href="[email protected]">weilingfeng</a>
*5:41:52 PM
*Apr 1, 2010
*
*/
public interface IuserDao {
public List findList();
}
3.新建IuserMysqlDao
/**
*
*/
package com.youxigu;

import java.util.List;

/**
* @author <a href="[email protected]">weilingfeng</a>
*5:44:51 PM
*Apr 1, 2010
*
*/
public class IuserMysqlDao implements IuserDao {
public List findList(){
System.out.println("从mysql查询数据列表");
return null;
}
}
4.新建IuserOracleDao
/**
*
*/
package com.youxigu;

import java.util.List;

/**
* @author <a href="[email protected]">weilingfeng</a>
*5:43:31 PM
*Apr 1, 2010
*
*/
public class UserOracleImpDao implements IuserDao {

/* (non-Javadoc)
* @see com.youxigu.IuserDao#findList()
*/
public List findList() {
System.out.println("从oracle查询用户信息");
return null;
}

}
5.新建userManager
/**
*
*/
package com.youxigu;

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

/**
* @author <a href="[email protected]">weilingfeng</a>
*5:46:37 PM
*Apr 1, 2010
*
*/
public class UserManager {
public IuserDao dao;

public IuserDao getDao() {
return dao;
}

public void setDao(IuserDao dao) {
this.dao = dao;
}

public static void main(String[] args) {
ApplicationContext cxt=new ClassPathXmlApplicationContext("applicationContext.xml");
UserManager manager=(UserManager)cxt.getBean("UserManager");
manager.getDao().findList();
}
}
6.applicationContext.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">

<bean id="UserManager" class="com.youxigu.UserManager">
<property name="dao" ref="IuserMysqlDao"></property>
</bean>

<bean id="IuserMysqlDao" class="com.youxigu.IuserMysqlDao"></bean>

</beans>
7.运行UserManager
从mysql查询数据列表
8.总结applicationContext.xml文件放在Web-Root/web-info/config/下面怎么会找不到呢

你可能感兴趣的:(DAO,spring,oracle,xml,mysql)