重新学习之spring第三个程序,整合struts2+spring
第一步:导入Struts2jar包+springIOC的jar包和Aop的Jar包

第二步:建立applicationContext.xml文件+struts.xml文件+web.xml文件
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
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"> <context-param>
<description>
将applicationContext.xml放在src目录下,依然能够找到该配置文件
</description> <param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param> <listener>
<description>
项目启动时,创建Ioc容器,将项目下所有费数据类创建对象,并注入,建立对象之间的关系
</description> <listener-class>
org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <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"
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/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!--
lazy-init:true 懒加载,初始ioc化容器的时候,不建立对象
lazy-init:false(默认) 不懒加载,初始化ioc容器的时候,就讲applicationContext.XML中所有配置的类的对象创建,并建立关系
scope:prototype每次取对应id的类的对象,都新创建一个
scope:singleton(默认)类似于单例模式,只要容器初始化一个类对象,以后所有的取用,都是取这一个
--> <!-- 通过setter方法,依赖注入对象。控制反转 -->
<bean id="UserAction " class="com.bjsxt.sxf.action.UserAction" scope="prototype" >
<property name="userDao" ref="UserDao" ></property>
</bean>
<bean id="UserDao" class="com.bjsxt.sxf.dao.UserDao" scope="prototype"></bean> <!-- 定义一个切面(连接点,切入点,通知) -->
<bean id="log" class="com.bjsxt.sxf.aop.MyAop"></bean>
<aop:config >
<!-- 切入点,将dao包下所有有参数或无参数传入的,有返回值或无返回值类型的公共方法,进行代理。 -->
<aop:pointcut expression="execution(public * com.bjsxt.sxf.dao.*.*(..))" id="logCut"/>
<!-- 通知,也就是代理对象中增强功能代码的编写 -->
<aop:aspect ref="log">
<!-- 环绕通知,有参数的传递,可对参数传递进行处理 -->
<aop:around method="aroundRun" pointcut-ref="logCut"/>
</aop:aspect>
</aop:config>
</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>
<!-- 如果请求地址=actionName!methodName ,则该配置需要进行设置,否则访问地址错误-->
<constant name="struts.enable.DynamicMethodInvocation" value="true" /> <!-- 开发模式 -->
<constant name="struts.devMode" value="true" /> <!-- 编码格式过滤 -->
<constant name="struts.i18n.encoding" value="utf-8"></constant> <!-- 告诉struts.xml不要自己通过反射new,对象,去spring的ioc容器中找
action中的class='spring中Ioc容器中对象的id'
annotation注解生成对象默认情况下id值为是:类名首字符小写
需要加jar包struts-spring-plugin..jar
-->
<constant name="struts.objectFactory" value="spring"></constant> <package name="default" namespace="/" extends="struts-default">
<!-- actionName!methodName请求方式的配置 -->
<action name="userAction" class="UserAction">
<result name="success">/page/success.jsp</result>
</action>
</package>
</struts>
第三步:测试(省略相关代码。)


重新学习之spring第三个程序,整合struts2+spring的更多相关文章
- 整合struts2+spring+hibernate
一.准备struts2+spring+hibernate所须要的jar包: 新建web项目并将jar包引入到project项目中. 二.搭建struts2环境 a.在 ...
- MyBatis学习-使用Druid连接池将Maybatis整合到spring
目录 前言 什么是Druid连接池 Druid可以做什么? 导入库包 连接oracle 连接mysql 导入mybatis 导入druid 导入spring-jdbc包 导入spring包 导入spr ...
- SSH之IDEA2017整合Struts2+Spring+Hibernate
转自:https://blog.csdn.net/sysushui/article/details/68937005
- 学习spring第三天
Spring第三天笔记 今日内容 Spring的核心之一 - AOP思想 (1) 代理模式- 动态代理 ① JDK的动态代理 (Java官方) ② CGLIB 第三方代理 (2) AOP思想在Spr ...
- Spring、Struts2+Spring+Hibernate整合步骤
所使用的Jar包: Hibernate: Spring(使用MyEclipse自动导入框架功能) Struts2: 注解包和MySql驱动包: 1.配置Hibernate和Spring: <be ...
- SSH三大框架的搭建整合(struts2+spring+hibernate)(转)
原文地址:http://blog.csdn.net/kyle0349/article/details/51751913 尊重原创,请访问原文地址 SSH说的上是javaweb经典框架,不能说100% ...
- SSH---整合Struts2&Spring&Hibernate(实例)
一.SSH回顾 Struts2:核心为过滤器+拦截器.过程:Filter--->FilterDispatcher-->ActionMapper-->ActionProxy--> ...
- 【转】Spring学习---Bean配置的三种方式(XML、注解、Java类)介绍与对比
[原文]https://www.toutiao.com/i6594205115605844493/ Spring学习Bean配置的三种方式(XML.注解.Java类)介绍与对比 本文将详细介绍Spri ...
- 【Java EE 学习 52】【Spring学习第四天】【Spring与JDBC】【JdbcTemplate创建的三种方式】【Spring事务管理】【事务中使用dbutils则回滚失败!!!??】
一.JDBC编程特点 静态代码+动态变量=JDBC编程. 静态代码:比如所有的数据库连接池 都实现了DataSource接口,都实现了Connection接口. 动态变量:用户名.密码.连接的数据库. ...
随机推荐
- 手把手教你学node.js之使用 superagent 与 cheerio 完成简单爬虫
使用 superagent 与 cheerio 完成简单爬虫 目标 建立一个 lesson 3 项目,在其中编写代码. 当在浏览器中访问 http://localhost:3000/ 时,输出 CNo ...
- Lyft Level 5 Challenge 2018 - Elimination Round
A. King Escape 签. #include <bits/stdc++.h> using namespace std; ], y[]; int f1(int X, int Y) { ...
- 牛客国庆集训派对Day5 Solution
A 璀璨光滑 留坑. B 电音之王 蒙特马利大数乘模运算 #include <bits/stdc++.h> using namespace std; typedef long ...
- 服务器负载、CPU性能判断
说在前面: 在linux操作系统中,我们一般查看系统的cpu负载情况常用的命令可以是uptime,top,还有vmstat等这些个都是可以有的.每个工具所提供的信息各不相同, 我这里要讨论的仅说cpu ...
- express+mongodb+mongoose简单入门
mongodb安装 window安装方法就不讨论了,比较简单~我们来看一下在linux下面的安装步骤~(这里需要一点linux的简单命令知识哈) 1.下载文件到服务器(先创建好自己想安装的目录)~ c ...
- springcloud16---zuul-filter
package com.itmuch.cloud; import org.springframework.boot.SpringApplication; import org.springframew ...
- 反射获取成员方法(Method)
1.1.1 反射公开的非静态的成员方法 Method getDeclaredMethod(String name,Class ... parameterTypes)获取某个方法. 说明: 1)在Cla ...
- 基于swing的MySQL可视化界面
个人记录贴... 代码过烂不宜参考.. 效果展示 1.选择需要打开的数据库,查看数据库下的表. 2.双击打开一个表 3.没有CRUD.... 代码 test-main: import shell.DB ...
- 20162326 qilifeng 2018-2019-2 《网络对抗技术》Exp0 Kali安装 Week1
<网络对抗技术>第1次作业 (一)作业任务 1.安装kali 2.设置共享文件夹 (二)操作过程 1.安装kali 因为之前安装过Oracle 的VM VirtualBox 所以直接 进入 ...
- 百度语音识别vs科大讯飞语音识别
一.结果 从笔者试验的结果来看,科大讯飞的语音识别技术远超百度语音识别 二.横向对比 科大讯飞语音识别 百度语音识别 费用 各功能的前5小时免费 全程免费 转换精准率 非常高 比较低 linux ...