2.集成Spring和Hibernate
1) Struts2和Spring2集成
1.1)将D:\JavaTools\struts-2.1.2\lib\下的
struts2-spring-plugin-2.1.2.jar复制到
D:\Project\Bitrac\WebRoot\WEB-INF\lib\
1.2)在web.xml文件中加入Spring配置:
<!--默认加载/WEB-INF 目录下的applicationContext.xml -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
加入后完整的文件内容如下:
- <?
xml
version
=
"
1.0
"
encoding
=
"
UTF-8
"
?>
- <
web-app
id
=
"
bitrac
"
version
=
"
2.4
"
xmlns
=
"
http://java.sun.com/xml/ns/j2ee
"
xmlns:xsi
=
"
http://www.w3.org/2001/XMLSchema-instance
"
xsi:schemaLocation
=
"
http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd
"
>
-
<
display-name
>
Bitrac Blog
</
display-name
>
-
-
<
filter
>
-
<
filter-name
>
Struts2
</
filter-name
>
-
<
filter-class
>
- org.apache.struts2.dispatcher.FilterDispatcher
-
</
filter-class
>
-
</
filter
>
-
-
<
filter-mapping
>
-
<
filter-name
>
Struts2
</
filter-name
>
-
<
url-pattern
>
/*
</
url-pattern
>
-
</
filter-mapping
>
-
-
<!--默认加载/WEB-INF 目录下的applicationContext.xml -->
-
<
listener
>
-
<
listener-class
>
org.springframework.web.context.ContextLoaderListener
</
listener-class
>
-
</
listener
>
-
-
<
welcome-file-list
>
-
<
welcome-file
>
index.jsp
</
welcome-file
>
-
</
welcome-file-list
>
-
- </
web-app
>
1.3)新建Struts配置文件Bitrac\src\default.xml,内容如下:
- <?
xml
version
=
"
1.0
"
encoding
=
"
UTF-8
"
?>
- <
!
DOCTYPE
struts
PUBLIC
-
"
-//Apache Software Foundation//DTD Struts Configuration 2.0//EN
"
-
"
http://struts.apache.org/dtds/struts-2.0.dtd
"
>
-
- <
struts
>
-
<
package
name
=
"
default
"
extends
=
"
struts-default
"
>
-
<
action
name
=
"
admincp
"
>
-
<
result
>
/admin/login.jsp
</
result
>
-
</
action
>
-
</
package
>
- </
struts
>
这个配置文件将用来存放前台的action配置
1.4)新建Struts配置文件Bitrac\src\admin.xml,内容如下:
- <?
xml
version
=
"
1.0
"
encoding
=
"
UTF-8
"
?>
- <
!
DOCTYPE
struts
PUBLIC
-
"
-//Apache Software Foundation//DTD Struts Configuration 2.0//EN
"
-
"
http://struts.apache.org/dtds/struts-2.0.dtd
"
>
-
- <
struts
>
-
<
package
name
=
"
admin
"
extends
=
"
struts-default
"
namespace
=
"
/admin
"
>
-
<
action
name
=
"
login
"
class
=
"
adminAction
"
method
=
"
login
"
>
-
<
result
name
=
"
success
"
>
/admin/index.jsp
</
result
>
-
<
result
name
=
"
input
"
>
/admin/login.jsp
</
result
>
-
</
action
>
-
</
package
>
- </
struts
>
这个文件将用来存放后台管理界面的Action配置
1.5)修改Bitrac\src\struts.xml,内容如下:
- <?
xml
version
=
"
1.0
"
encoding
=
"
UTF-8
"
?>
- <
!
DOCTYPE
struts
PUBLIC
-
"
-//Apache Software Foundation//DTD Struts Configuration 2.0//EN
"
-
"
http://struts.apache.org/dtds/struts-2.0.dtd
"
>
-
- <
struts
>
-
<
constant
name
=
"
struts.devMode
"
value
=
"
true
"
/>
-
<
constant
name
=
"
struts.configuration.xml.reload
"
value
=
"
true
"
/>
-
<
constant
name
=
"
struts.action.extension
"
value
=
"
jspx
"
/>
-
-
<
include
file
=
"
default.xml
"
/>
-
<
include
file
=
"
admin.xml
"
/>
- </
struts
>
这里配置了一些全局常量,struts.action.extentsion是访问action时的后缀,通常用的有action或者do,我的习惯是用jspx,例如/admin/login.jspx,将调用admin.xml里定义的login action。
1.6)新建Spring配置文件
- <?
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:aop
=
"
http://www.springframework.org/schema/aop
"
-
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/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
"
>
-
-
<
bean
name
=
"
adminAction
"
class
=
"
com.albertsong.bitrac.action.AdminAction
"
/>
- </
beans
>
注
意这里的bean
name是adminAction,再看Bitrac\src\admin.xml里的class="adminAction",Spring和
Struts的结合点就在这里,后台处理这一结合的是struts2-spring-plugin-2.1.2.jar。如果不使用spring,在
admin.xml中将是class="com.albertsong.bitrac.action.AdminAction"。
分享到:
相关推荐
struts2+spring2.5+hibernate3.2整合完整项目,带数据库脚本 ,mysql,tomcat,myeclipse完整工程
这是一个struts 1.2 + spring 2.5 + hibernate 3.2框架demo, 运行环境为eclipse 3.2 + tomcat 5.5 + oracle 11g
struts2.1 + spring 2.5 + hibernate 3.2 增删改查 详细例子
struts2+spring2.5+hibernate3.2 找了半天没看到。自己整了一个。
cdst ssh代码生成器,免费的,功能强悍的struts2+spring2.5+hibernate3.2的一套 代码生成系统。.zip cdst ssh代码生成器,免费的,功能强悍的struts2+spring2.5+hibernate3.2的一套 代码生成系统。.zip cdst ssh代码...
struts2+spring2.5+hibernate3.2 + freemarker 全新功能实现的增删改查+freemarker 摸版 struts2 的方式自己去看简单。 spring2.5 是用注释来注入 hibernate3.2 是用ejb3注解映射关系 hibernate3 +个属性可以自动...
非常好的学习资料 struts2+spring2.5+hibernate3.2大型项目spring mvc
struts2+spring2.5+hibernate3.2 例子
ecside+struts2+spring2.5+hibernate3.2 最近做的一个工程,太大了,只好分成几个发布.相关的.jar,和ecside用到的东西,自己找下
struts2+Spring2.5+Spring3.2)实现登录.struts2+Spring2.5+Spring3.2)实现登录.struts2+Spring2.5+Spring3.2)实现登录。
NULL 博文链接:https://gaobo424.iteye.com/blog/870162
Struts2+Spring2.5+Hibernate3.2集成实例开发2 Struts2+Spring2.5+Hibernate3.2集成实例开发2
Struts2.0+spring2.5+hibernate3.2
1、可以运行(发布后,删除\Tomcat 6.0\webapps\ssh\WebRoot\WEB-INF\lib下的asm-2.2.3.jar) 2、采用Struts1.2 + Spring2.5 + Hibernate3.2 整合开发 3、SSH入门级实例
struts2+spring2.5+hibernate3.2整合所需的基本jar包,希望大家用得着。
Struts2+Spring2.5+Hibernate3.2集成实例开发 附带我本人写的一个实例,如果默认数据库Oracle10g ,可以根据实际情况调整;文件较大,分为两个部分下载,同时下在完成后,执行Struts2+Spring+Hibernate.part1.rar...
这两天做的一个适合初学者的SSH框架整合的例子,相信对初学者会有一定帮助。
struts2.1.6+spring2.5+hibernate3.2整合实例,绝对原创,绝对运行正常,jar文件的截图和sql都有 由于自己学习时耗了很多时间所以要分,请大家理解,有什么问题可以和我联系http://blog.163.com/lzy_eagle
ecside+struts2+spring2.5+hibernate3.2,这是最近的做的一个项目,用到了目前好几个比较流行的框架,ecside\e3\ext