Struts2 Spring2 整合_Java实例教程_Java_软件编程
来源:百度文库 编辑:神马文学网 时间:2024/04/29 15:47:43
Struts2 Spring2 整合
要实现与Struts与Spring的集成有如下几步
1. 将struts2-spring-plugin-2.0.8.jar文件包含到我们的应用中,放到WEB-INF/lib目录下面即可.
2.配置Spring监听器.
将下面一段话插入到web.xml文件中,同时将spring.jar文件放到WEB-INF/lib目录下面。
org.springframework.web.context.ContextLoaderListener
3.利用Spring配置文件来注册对象
(1)这里有一点得注意:使用spring配置文件注册action对象,
中使用 ID 来定义,class=“action包引用类名”
例如:
abstract="false" lazy-init="default" autowire="default">
(2) 在struts.xml文件中:中的class为spring
配置文件中的 ID
/result.jsp
这之后的步骤就和我们使用单独使用Spring一样了,现在我们就已经完成了 Struts与Spring的集成了。这里有一点要注意的是,我们还要指定Spring配置文件的地点,默认情况下,容器会到WEB-INF目录下面去寻 找applicationContext.xml文件。如果我们想指定别的地方的配置文件或者指定多个配置文件,可以通过在web.xml文件中定义 context-param元素来指定,如下所示:
contextConfigLocation
/WEB-INF/applicationContext.xml,classpath:applicationContext-*.xml
上面一段话表示WEB-INF下面的applicationContext.xml文件以及classpath下面的所有匹配applicationContext-*.xml模式的文件都会作为Spring配置文件被装载
web.xml 的源代码清单
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
contextConfigLocation
/WEB-INF/applicationContext*.xml,classpath*:applicationContext*.xml
struts2
org.apache.struts2.dispatcher.FilterDispatcher
struts2
/*
index.jsp
org.springframework.web.context.ContextLoaderListener
struts.xml
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
value="type" />
/HelloPOJO.jsp
applicationContext.xml
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
Spring Struts 2 注入
文章出处:http://www.diybl.com/course/3_program/java/javashl/2008419/110506.html
要实现与Struts与Spring的集成有如下几步
1. 将struts2-spring-plugin-2.0.8.jar文件包含到我们的应用中,放到WEB-INF/lib目录下面即可.
2.配置Spring监听器.
将下面一段话插入到web.xml文件中,同时将spring.jar文件放到WEB-INF/lib目录下面。
org.springframework.web.context.ContextLoaderListener
3.利用Spring配置文件来注册对象
(1)这里有一点得注意:使用spring配置文件注册action对象,
例如:
(2) 在struts.xml文件中:
配置文件
这之后的步骤就和我们使用单独使用Spring一样了,现在我们就已经完成了 Struts与Spring的集成了。这里有一点要注意的是,我们还要指定Spring配置文件的地点,默认情况下,容器会到WEB-INF目录下面去寻 找applicationContext.xml文件。如果我们想指定别的地方的配置文件或者指定多个配置文件,可以通过在web.xml文件中定义 context-param元素来指定,如下所示:
/WEB-INF/applicationContext.xml,classpath:applicationContext-*.xml
上面一段话表示WEB-INF下面的applicationContext.xml文件以及classpath下面的所有匹配applicationContext-*.xml模式的文件都会作为Spring配置文件被装载
web.xml 的源代码清单
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
org.apache.struts2.dispatcher.FilterDispatcher
org.springframework.web.context.ContextLoaderListener
struts.xml
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
applicationContext.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
文章出处:http://www.diybl.com/course/3_program/java/javashl/2008419/110506.html
Struts2 Spring2 整合_Java实例教程_Java_软件编程
Struts2 Spring2 整合_Java实例教程_Java_软件编程
struts2.1.8 + spring2.5.6 + hibernate3.3.2整合
Struts2.1.6与Spring2.5.6框架整合q
Struts2.1.6与Spring2.5.6框架整合1
Struts2.1.6与Spring2.5.6框架整合fffffff
Struts2.1.6与Spring2.5.6框架整合sds
struts2.1.8 + spring2.5.6 + hibernate3.3.2整合的..qqq.
Struts2.1.6与Spring2.5.6框架整合222
Struts2.1.6+Spring2.5+Hibernate3.2
Spring2.5、Struts2、Ibatis开发框架
Joan's javaworld - Struts2+Spring2.5+Hibernat...
Struts2.1.6+Spring2.5+Hibernate3.2qqq
配置struts2.0.6+spring2.0.3+hibernane3备忘
struts2整合tiles及配置
Spring2.5、Struts2、Ibatis开发框架搭建(一1)
软件整合
整合Struts2与Spring的步骤(转)
Struts2与Spring、Hibernate三者整合
整合Struts2与Spring的步骤assas
Spring2.0与Hibernate3整合 - J2EE之巅 - BlogJava
Spring2.0与Hibernate3整合 - J2EE之巅 - BlogJava
Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解实例详解(一)
Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解实例详解(四)