整合ssi虽然原理比较简单,但在实际操作的时候还是容易出错的,在这里也记录一下...
各个组件的版本号:struts2.1 spring2.5 ibatis2.3
struts2.1需要的包
首先是struts2.1必须的包:
然后是要与spring集成需要的包:struts2-spring-plugin-2.1.6.jar
spring2.5需要的包
这里用的是集成了spring所有模块的包:spring.jar
ibatis2.3需要的包
ibatis-2.3.*.*.jar
web.xml的配置
<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->
1
<?
xmlversion="1.0"encoding="UTF-8"
?>
2
<
web-app
version
="2.4"
xmlns
="http://java.sun.com/xml/ns/j2ee"
3
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
4
xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee
5
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>
6
<
filter
>
7
<
filter-name
>
struts2
</
filter-name
>
8
<
filter-class
>
9
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
10
</
filter-class
>
11
</
filter
>
12
<
listener
>
13
<
listener-class
>
14
org.springframework.web.context.ContextLoaderListener
15
</
listener-class
>
16
</
listener
>
17
<
filter-mapping
>
18
<
filter-name
>
struts2
</
filter-name
>
19
<
url-pattern
>
/*
</
url-pattern
>
20
</
filter-mapping
>
21
<
welcome-file-list
>
22
<
welcome-file
>
login.jsp
</
welcome-file
>
23
</
welcome-file-list
>
24
</
web-app
>
25
applicationContext.xml的配置
<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->
<?
xmlversion="1.0"encoding="UTF-8"
?>
<
beans
xmlns
="http://www.springframework.org/schema/beans"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop
="http://www.springframework.org/schema/aop"
xmlns:tx
="http://www.springframework.org/schema/tx"
xsi:schemaLocation
="
http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
>
<
bean
id
="dataSource"
class
="org.springframework.jdbc.datasource.DriverManagerDataSource"
>
<
property
name
="driverClassName"
>
<
value
>
org.gjt.mm.mysql.Driver
</
value
>
</
property
>
<
property
name
="url"
>
<
value
>
jdbc:mysql://localhost:3306/test
</
value
>
</
property
>
<
property
name
="username"
>
<
value
>
root
</
value
>
</
property
>
<
property
name
="password"
>
<
value
></
value
>
</
property
>
</
bean
>
<
bean
id
="sqlMapClient"
class
="org.springframework.orm.ibatis.SqlMapClientFactoryBean"
>
<
property
name
="dataSource"
ref
="dataSource"
/>
<
property
name
="configLocation"
value
="WEB-INF/sql-map-config.xml"
/>
</
bean
>
<
bean
id
="sqlMapClientTemplate"
class
="org.springframework.orm.ibatis.SqlMapClientTemplate"
>
<
property
name
="sqlMapClient"
ref
="sqlMapClient"
/>
</
bean
>
<!--
其他配置,如DAO,Action--/>
</beans>
sql-map-config.xml的配置
<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->
<?
xmlversion="1.0"encoding="UTF-8"
?>
<!
DOCTYPEsqlMapConfig
PUBLIC"-//ibatis.apache.org//DTDSQLMapConfig2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd"
>
<
sqlMapConfig
>
<
settings
useStatementNamespaces
="true"
/>
<
sqlMap
resource
="ssi/persistance/sqlmap/user_SqlMap.xml"
/>
</
sqlMapConfig
>
具体sql-map文件的配置,这里就不写了,我也是刚刚学习ibatis,呵呵,由于最近马上就要开发了,就找了工具来加快速度,ibatis官方提供的ibator(原来叫abator)这个工具相当猛啊,还在学习中...
在配置过程当中,特别需要注意各个配置文件的存放位置,比如对于applicationContext.xml来说,默认应该存放在WEB-INF文件夹中,如果想放到类路径上去,需要在web.xml里面配置,一般配置在web.xml的开头部分:
<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->
<
context-param
>
<
param-name
>
contextConfigLocation
</
param-name
>
<
param-value
>
classpath:applicationContext.xml
</
param-value
>
</
context-param
>