临时抱佛脚之Spring学习笔记

来源:互联网 发布:电力系统波形分析软件 编辑:程序博客网 时间:2024/06/10 22:24

       好久都没有碰过spring的知识了,最近心血来潮,希望能好好看看。当然啦,时间也不是很充分,当然,我个人而言也确实没有太多的精力,周六日还有一些比较棘手的事情,只能抽自己还算清楚的时候写点代码,做下总结了。

      首先是以java project的方式来运行spring程序,其实算是测试一下是 怎样使用spring容器吧,我是通过看视频来学习 的,讲得很细致,操作也很清晰 明了。我很郁闷的是spring的jar包和源码包在官方网站竟然找不到下载的地方,而且在 其他地方也找不到比较好的资源,没有办法,就将就着使用到了哪个包就找哪个包,然后引用到程序中。配置文件的模版大致如下:

<?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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="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/tx hsttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd" default-autowire="byName" default-lazy-init="true"> </beans>
配置文件大多数 情况下是放在类路径下,就是src目录下。加载配置文件的方式也有两种,一种是在类路径下寻找配置 文件,当然这也是最常用的,其调用方法 为:

ApplicationContext cxt=new ClassPathXmlApplicationContext(new String[]{"beans.xxml"});其中配置文件可以 是一个,也可以是多个。还有一种方式是在文件系统路径下去寻找,这要用到绝对路径,考虑到程序的移植问题,这样方法可操作性不强。(待续)