Spring_36_集成 Struts2
来源:互联网 发布:福昕阅读器 for linux 编辑:程序博客网 时间:2024/06/14 11:41
- 他人的笔记和基本思路
- Spring 如何整合 Struts2 ?
1). 整合目标 ? 使 IOC 容器来管理 Struts2 的 Action!
2). 如何进行整合 ?
①. 正常加入 Struts2
②. 在 Spring 的 IOC 容器中配置 Struts2 的 Action
注意: 在 IOC 容器中配置 Struts2 的 Action 时, 需要配置 scope 属性, 其值必须为 prototype
<bean id="personAction" class="com.atguigu.spring.struts2.actions.PersonAction" scope="prototype"> <property name="personService" ref="personService"></property> </bean>
③. 配置 Struts2 的配置文件: action 节点的 class 属性需要指向 IOC 容器中该 bean 的 id
<action name="person-save" class="personAction"> <result>/success.jsp</result></action>
④. 加入 struts2-spring-plugin-2.3.15.3.jar
3). 整合原理: 通过添加 struts2-spring-plugin-2.3.15.3.jar 以后, Struts2 会先从 IOC 容器中
获取 Action 的实例.
if (appContext.containsBean(beanName)) { o = appContext.getBean(beanName);} else { Class beanClazz = getClassInstance(beanName); o = buildBean(beanClazz, extraContext);}
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <!-- 配置 Spring 配置文件的名称和位置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- 启动 IOC 容器的 ServletContextListener --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 配置 Struts2 的 Filter --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="person" class="com.atguigu.spring.struts2.beans.Person"> <property name="username" value="spring"></property> </bean> <bean id="personService" class="com.atguigu.spring.struts2.services.PersonService"></bean> <!-- 注意: 在 IOC 容器中配置 Struts2 的 Action 时, 需要配置 scope 属性, 其值必须为 prototype --> <bean id="personAction" class="com.atguigu.spring.struts2.actions.PersonAction" scope="prototype"> <property name="personService" ref="personService"></property> </bean></beans>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <!-- Spring 整合 Struts2 时, 在 Struts2 中配置的 Spring 的 Action 的 class 需要指向 IOC 容器中该 bean 的 id --> <action name="person-save" class="personAction"> <result>/success.jsp</result> </action> </package></struts>
0 0
- Spring_36_集成 Struts2
- springboot 集成hibernate 集成struts2
- struts2 集成 click framework
- struts2.与spring集成
- struts2.与spring集成
- Struts2+JQuery+JSON集成
- Struts2 集成 Dojo
- Struts2与Spring集成
- Spring与Struts2集成
- Spring与Struts2集成
- struts2+spring+iBatis集成
- Struts2 Spring 集成 配置文件
- struts2.1.6集成tiles2
- Spring Struts2集成步骤
- Spring Struts2集成步骤
- Struts2集成Spring
- struts2+jquery+json集成
- struts2集成sitemesh
- java hashCode详解
- java压缩解压缩ZipFile完整源码-可以直接拿来用
- C# 6 与 .NET Core 1.0 高级编程_0
- [UVa10779]Collectors Problem(最大流)
- <The C programming language> 5.11 函数指针 “函数名称就是函数的地址?”
- Spring_36_集成 Struts2
- View位置信息
- Python机器视觉编程环境搭建方法
- 这是我的第一个博客 我喜欢这里
- Chrome 控制台实用实用命令
- A strange lift HDU - 1548
- 初学Hibernate之开发准备
- 进程间通信——信号
- BZOJ 1176: [Balkan2007]Mokia CDQ分治,容斥