以下配置方式主要来自尚上堂马士兵老师
1.需要的jar包列表
<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 415 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1593833729 1073750107 16 0 415 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Verdana","sans-serif"; mso-fareast-font-family:宋体; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->
jar 包名称 | 所在位置 | 说明 |
antlr-2.7.6.jar | hibernate/lib/required | 解析 HQL |
aspectjrt | spring/lib/aspectj | AOP |
aspectjweaver | .. | AOP |
cglib-nodep-2.1_3.jar | spring/lib/cglib | 代理,二进制增强 |
common-annotations.jar | spring/lib/j2ee | @Resource |
commons-collections-3.1.jar | hibernate/lib/required | 集合框架 |
commons-fileupload-1.2.1.jar | struts/lib | struts |
commons-io-1.3.2 | struts/lib | struts |
commons-logging-1.1.1 | 单独下载,删除 1.0.4 (struts/lib) | struts spring |
dom4j-1.6.1.jar | hibernate/required | 解析 xml |
ejb3-persistence | hibernate-annotation/lib | @Entity |
freemarker-2.3.13 | struts/lib | struts |
hibernate3.jar | hibernate |
|
hibernate-annotations | hibernate-annotation/ |
|
hibernate-common-annotations | hibernate-annotation/lib |
|
javassist-3.9.0.GA.jar | hiberante/lib/required | hibernate |
jta-1.1.jar | .. | hibernate transaction |
junit4.5 |
|
|
mysql- |
|
|
ognl-2.6.11.jar | struts/lib |
|
slf4j-api-1.5.8.jar | hibernate/lib/required | hibernate-log |
slf4j-nop-1.5.8.jar | hibernate/lib/required |
|
spring.jar | spring/dist |
|
struts2-core-2.1.6.jar | struts/lib |
|
xwork-2.1.2.jar | struts/lib | struts2 |
commons-dbcp | spring/lib/jarkata-commons |
|
commons-pool.jar | .. |
|
struts2-spring-plugin-2.1.6.jar | struts/lib |
|
2.步骤
(1)加入jar包
(2)首先整合spring + hibernate
(a) 建立对应的package
1. dao/dao.impl、model、service/service.impl、test
(b) 建立对应的接口与类框架
(c) 建立spring配置文件
(d) 建立数据库
(e) 加入hibernate注解
1. 在实体类上加上相应的注解@Entity@Id
2. 在beans中配置对应的实体类
(f) 写dao、service的实现
(g) 加入spring注解
1. 在对应servic及dao实现中加入@Component,让sping容器对其进行初始化
2. 在service上加上@Transactional或者使用xml配置方式
3. 在dao中注入sessionFactory
4. 在service中注入dao
(h)写测试类
(3)整合struts2
(a)结合点:stuts的action由spring产生
(b)步骤:
1. 修改web.xml,加入struts2的filter
2. 再加入spring的listener,webapp已启动spring容器就会初始化
3. 规划struts的action和jsp的展现
4. 加入struts.xml,修改配置有spring代替struts产生action对象
5. 修改struts.xml中的action配置,把类名改为bean对象名称,注意@Scope("prototype")
<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 415 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1593833729 1073750107 16 0 415 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Verdana","sans-serif"; mso-fareast-font-family:宋体; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:252131462; mso-list-type:hybrid; mso-list-template-ids:751181458 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;} @list l0:level1 {mso-level-tab-stop:21.0pt; mso-level-number-position:left; margin-left:21.0pt; text-indent:-21.0pt;} @list l0:level2 {mso-level-number-format:alpha-lower; mso-level-text:"%2/)"; mso-level-tab-stop:42.0pt; mso-level-number-position:left; margin-left:42.0pt; text-indent:-21.0pt;} @list l0:level3 {mso-level-number-format:roman-lower; mso-level-tab-stop:63.0pt; mso-level-number-position:right; margin-left:63.0pt; text-indent:-21.0pt;} @list l0:level4 {mso-level-tab-stop:84.0pt; mso-level-number-position:left; margin-left:84.0pt; text-indent:-21.0pt;} @list l0:level5 {mso-level-number-format:alpha-lower; mso-level-text:"%5/)"; mso-level-tab-stop:105.0pt; mso-level-number-position:left; margin-left:105.0pt; text-indent:-21.0pt;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} --> (c)struts 的读常量:
1. struts-default.xml
2. struts-plugin.xml
3. struts.xml
4. struts.properties
5. web.xml
(d)中文问题:
1. Struts2.1.8 已经修正,只需要改 i18n.encoding = gbk
2. 使用 spring 的 characterencoding
3. 需要严格注意 filter 的顺序
4. 需要加到 Struts2 的 filter 前面
(e)LazyInitializationException
1. OpenSessionInViewFilter
2. 需要严格顺序问题
3. 需要加到 struts2 的 filter 前面