1,新建web项目
2,导入jar包
3,编写配置文件
<?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.xsd">
<bean id="userDao" class="com.songyan.demo1.UserDaoImpl" ></bean>
</beans>
4,新建包
5,新建接口类
package com.songyan.demo1;
public interface UserDao {
public void say();
}
6,新建接口的实现类
package com.songyan.demo1;
public class UserDaoImpl implements UserDao{
public void say()
{
System.out.println("UsdeDao say helloWord");
}
}
7,编写测试类
package com.songyan.demo1;
import javax.xml.registry.infomodel.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Test {
public static void main(String[] args) {
//初始化容器,加载xml
ApplicationContext application =new ClassPathXmlApplicationContext("applicationContext.xml");
//通过容器获取javabean对象实例
UserDao userDao=(UserDao)application.getBean("userDao");
//调用实例的方法
userDao.say();
}
}
8,目录