spring的简单编程步骤
来源:互联网 发布:javascript插件编写 编辑:程序博客网 时间:2024/04/28 15:43
1.导入jar包
a.spring.jar
b.commons-logging.jar
2.在src下新建applicationContext.xml配置文件
3.修改applicationContext.xml,将各种组件(Bean)纳入到Spring的管理中
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"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
</beans>
4.新建接口
5.新建接口实现类
6.修改applicationContext.xml,在<beans></beans>中配置实现类的实例化
例子如下:
<bean id="feeDAO(可用接口名)" class="com.baidu.xxx(实现类的路径)"></bean>
7.测试
main函数中
//根据conf指定的配置实例化spring容器
String conf = "applicationContext.xml";
ApplicationContext ac =new ClassPathXmlApplicationContext(conf);
//通过spring容器获取定义的Bean对象
FeeDAO feeDao =(FeeDAO)ac.getBean("feeDAO");
//使用FeeDAO
feeDao.xxx();
- spring的简单编程步骤
- hibernate简单的编程步骤
- struts2的简单的编程步骤
- Spring切面编程步骤
- Spring AOP 编程步骤
- JDBC 简单编程步骤
- 整合spring的shiro 的简单搭建步骤
- spring mvc + freemarker 的简单实现全步骤
- 备份python写简单socket编程的步骤
- 用Eclipse完成C语言编程的几个简单步骤
- 网络编程基础-简单步骤
- spring简单的AOP编程小结
- Spring AOP 编程最简单的例子
- spring aop简单编程
- 【spring boot】spring boot简单配置web小程序的步骤
- 简单破解的简单步骤
- JDBC编程的步骤
- JDBC编程的步骤
- Socket编程 消息传送 TCP协议(窗口实现) 服务器
- 软件工程——需求分析
- Linux查看ip的命令详解
- ios 手势 事件
- 理解虚函数
- spring的简单编程步骤
- android 常见错误
- [VBA] 以二进制方式打开文件
- 伪随机数转换真随机数应用,一个公平的抽奖解决方案。
- 百度地图BMap API的应用实例
- 靠山山会倒,靠人人会跑
- gridcontrol 首选身份证明--以用户 oracle 的身份连接 失败
- Js实现当前点击a标签变色,其他a标签回复原色
- CentOS下SVN简介、下载、安装