第三天
1.Ioc_XDoclet学习,XDoclet使用 (三个配置文件,一个Bean中要写的标注,xDoclet的jar包)
配置Ant(连接spring的模板,还可以合并手写的spring-bean.xml)来实现xml的自动生成(bin/config.xml)
Ant的build.xml (关键配置文件)
<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorld" default="gen-spring-conf" basedir=".">
<property name="src.dir" value="src" /> //Bean
<property name="lib.dir" value="lib" /> //classpath
<property name="conf.dir" value="conf" /> //自已定义的配置文件,可以和自动生成的合并.
<property name="build.dir" value="bin" /> //生成后的,
<property name="template.dir" value="template" /> //使用模板的文件夹
<!-- 定义Classpath -->
<path id="master-classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<!-- 编译java源代码 -->
<target name="compile">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" target="1.5" debug="on" debuglevel="lines">
<classpath refid="master-classpath"/>
<src path="${src.dir}"/>
</javac>
</target>
<!--关键: 使用XDoclet生成配置文件 -->
<target name="gen-spring-conf" depends="compile">
<!-- 定义Ant任务 -->
<taskdef name="springdoclet"
classname="xdoclet.modules.spring.SpringDocletTask"
classpathref="master-classpath"
/>
<!-- 生成配置文件 -->
<springdoclet
destDir="${build.dir}" //目标
mergeDir="${conf.dir}" //要合并的
force="true"
excludedtags="@version,@author,@todo" //不读的标注
>
<fileset dir="${src.dir}" includes="**/*.java" />
<springxml
xmlencoding="UTF-8"
templateFile="${template.dir}/custom_spring_xml.xdt"
destinationFile="config.xml"
/>
</springdoclet>
</target>
</project>
不自动生成xml的写法:(是直接把手动写的复制到bin中)
<!-- 编译java源代码 -->
<target name="compile" depends="init">
<mkdir dir="${build.dir}" />
<javac destdir="${build.dir}">
<classpath refid="master-classpath"/>
<src path="${src.dir}"/>
</javac>
<!-- 复制beans.xml -->
<copy todir="${build.dir}">
<fileset file="${src.dir}/beans.xml"/>
</copy>
</target>
手写的配置spring-beans.xml(可以没有此文件)
<!-- pre-defined beans -->
<bean id="date" class="java.util.Date" />
<bean id="systemStartTime" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/systemStartTime" />
</bean>
模板 custom_spring_xml.xdt(通用,也可扩展)
( 在《Spring 2.0核心技术与最佳实践》
"光盘/software/xdoclet_with_javadoc-1.5/custom_spring_xml.xdt"
由于篇幅原因,此处就不贴出源码来了.)
XDoclet
在Bean中的标注:
类
/**
* @spring.bean id="basicBean" scope="prototype"
*/
/**
* @spring.bean ref="basicBean"
*/
public void setBasic(BasicBean basicBean)
属性
/**
* @spring.property value="100"
*/
/**
* @spring.property list="2.32,9.23,10.3" 强类型的
*/
public void setPrices(List<Float> prices) {
/**
* @spring.property list="1,1,2,3,5,8" 数组的
*/
public void setFibonacci(int[] fibonacci)
/**
* @spring.property setRef="basicBean,constructorBean,listBean"
*/
public void setCups(Set cups)
构造
/**
* @spring.constructor-arg type="int" value="100"
* @spring.constructor-arg type="int" value="200"
*/
/**
* @spring.bean id="exampleBean" init-method="init"
*/
/**
* @spring.property listRef="basicBean,constructorBean"
*/
public void setChildren(List children) {}
最后运行build.xml,就可以自动生成配置文件bin/config.xml了.成功了!!!
附:xDoclet的jar包在 "光盘/software/xdoclet_with_javadoc-1.5../lib"中
2.AOP思想为复辅
AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程
Gof即Gang of four,也就是四人幫的意思,該設計模式名書是由Erich Gamma、Richard Helm、Ralph Johnson與John Vissides所共同整理撰寫的設計模式介面,內容包括23種設計模式.(http://baike.baidu.com/view/1082055.htm)
3.www.livebookstore.net 研究 livebookstore,学习所有的知识点.
预处理语句怎么写 *.bat,HSQLDB数据库?
Live Bookstore安装指南(Windows平台)
1. 安装JDK 5
Live Bookstore只能运行在Java 5或更高版本的Java虚拟机上,不支持JDK 1.4.x及更早版本。请运行本书配套光盘中的JDK 5.0安装程序,完成JDK 5的安装,然后,设置以下环境变量:
JAVA_HOME=<JDK 5的安装目录>
Path=%JAVA_HOME%/bin;<其他...>
要测试环境变量,请打开命令提示符,然后输入以下命令:
C:/>java -version
应当看到类似"java version 1.5.0_08"的提示信息。否则,请检查环境变量JAVA_HOME和Path的设置。
2. 安装Ant(可选)
Ant是构建Live Bookstore必需的工具。Eclipse 3.2已经内置了Ant,如果需要脱离Eclipse构建工程,就需要安装Ant。
将本书配套光盘中的Ant压缩包解压到本地硬盘上,然后设置以下环境变量:
ANT_HOME=<Ant根目录>
Path=%ANT_HOME%/bin;%JAVA_HOME%/bin;<其他...>
要测试环境变量,请打开命令提示符,然后输入以下命令:
C:/>ant -h
应当看到Ant的帮助信息。否则,请检查环境变量ANT_HOME和Path的设置。
3. 安装Resin 3.1
Resin 3.1是Live Bookstore运行时的Web服务器,将从本书配套光盘中的Resin 3.1压缩包解压到本地硬盘上,然后设置以下环境变量:
将本书配套光盘中的resin压缩包解压到本地硬盘上,然后设置以下环境变量:
RESIN_HOME=<Resin 3.1根目录>
要测试Resin服务器是否能正常启动,请打开命令提示符,然后输入以下命令:
C:/>%RESIN_HOME%/httpd
应当弹出Resin服务器的控制窗口。否则,请检查环境变量RESIN_HOME的设置。
要关闭Resin服务器,只需在Resin的控制窗口上点击"Quit"按钮。
Resin 3.1默认的字符编码是ISO-8859-1,如果中文不能正常显示,请用配套光盘中的app-default.xml替换Resin根目录下的/conf/app-default.xml文件,或者手动修改app-default.xml文件的相关部分:
将
<servlet servlet-name="resin-file"
servlet-class="com.caucho.servlets.FileServlet"/>
改为:
<servlet servlet-name="resin-file"
servlet-class="com.caucho.servlets.FileServlet">
<init>
<character-encoding>utf-8</character-encoding>
</init>
</servlet>
4. 启动Live Bookstore应用程序
将本书配套光盘中的源代码目录source/livebookstore复制到本地硬盘,然后执行以下命令:
启动HSQLDB数据库:db_start.bat
(不要关闭HSQLDB的命令行窗口)
启动Resin:resin_start.bat
5. 测试Live Bookstore应用程序
打开浏览器,在地址栏输入:
http://localhost:8080/
稍等片刻(第一次访问需要编译JSP,时间稍长),应当出现Live Bookstore的首页。
自带的HSQLDB已经创建了两个用户:
管理员用户
登录名:admin
口令:livebookstore
普通用户
登录名:live
口令:livebookstore
6. 其他
Live Bookstore应用程序的根目录下还有如下目录:
api-doc
完整的API文档,可以使用Ant命令"ant apidoc"重新生成
auto-gen
自动生成的创建数据库表的脚本,可以使用Ant命令"ant make-schema"重新生成
db
HSQLDB的数据库文件