SSH框架分模块开发
------------------siwuxie095
SSH 框架分模块开发
1、在 Spring 核心配置文件中配置多个内容,容易造成
配置混乱,不利于维护
「分模块开发主要针对 Spring 核心配置文件」
2、把 Spring 核心配置文件中的一部分配置放到单独的
配置文件中,再在 Spring 核心配置文件中引入单独的配
置文件即可
3、一般情况下,建议把 Action 对象的配置放到单独的
配置文件中
「因为其它的配置基本不变,只有 Action 对象的配置在
不断重复」
如:
user.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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 配置 Action 对象 --> <bean id="userAction" class="com.siwuxie095.action.UserAction" scope="prototype"> <property name="userService" ref="userService"></property> </bean> <!-- 配置 Service 对象 --> <bean id="userService" class="com.siwuxie095.service.UserService"> <property name="userDao" ref="userDaoImpl"></property> </bean> <!-- 配置 Dao 实现类对象 --> <bean id="userDaoImpl" class="com.siwuxie095.dao.impl.UserDaoImpl"> <property name="hibernateTemplate" ref="hibernateTemplate"></property> </bean> <!-- 配置 HibernateTemplate 对象 --> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate"> <!-- 注入 SessionFactory 对象 --> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 关于 HibernateTemplate 对象的配置,其实也可以放在核心配置文件中, 因为它也是基本不变的 其实关于分模块开发,把任何一部分拿出去放到单独的配置文件中都可以, 只是建议把 Action 对象的配置放到单独的配置文件中,因为只有 Action 对象的配置是不断重复的,而其它的配置却是基本不变的 --> </beans> |
在 applicationContext.xml 中引入 user.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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- (1) --> <!-- 配置 C3P0 连接池 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="com.mysql.jdbc.Driver"/> <!-- jdbc:mysql:///test_db 是 jdbc:mysql://localhost:3306/test_db 的简写 --> <property name="jdbcUrl" value="jdbc:mysql:///test_db"/> <property name="user" value="root"/> <property name="password" value="8888"/> </bean> <!-- SessionFactory 对象的创建交给 Spring 进行管理 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <!-- 数据库配置原本是在 Hibernate 核心配置文件中配置的, 现在 Hibernate 核心配置文件不存在了,所以在这里注 入 dataSource LocalSessionFactoryBean 中有相关属性,所以可以 注入 --> <property name="dataSource" ref="dataSource"></property> <!-- 配置 Hibernate 基本信息 --> <property name="hibernateProperties"> <props> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <!-- 原来的配置: <prop key="hibernate.current_session_context_class">thread</prop> 在 SSH 框架整合中会报错,要么将这个配置删了,要么改成如下配置 参考链接:http://blog.csdn.net/maoyuanming0806/article/details/61417995 --> <prop key="hibernate.current_session_context_class"> org.springframework.orm.hibernate5.SpringSessionContext </prop> </props> </property> <!-- 引入映射配置文件 --> <property name="mappingResources"> <list> <value>com/siwuxie095/entity/User.hbm.xml</value> <!-- <value>....</value> --> </list> </property> </bean> <!-- (2) --> <!-- 引入 src 下的 user.xml 配置文件 其实 classpath 可以省略不写,即: <import resource="user.xml"/> 建议写上 --> <import resource="classpath:user.xml"/> <!-- (3) --> <!-- 配置事务管理器 HibernateTransactionManager --> <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <!--注入 SessionFactory 对象 --> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 开启事务注解 --> <tx:annotation-driven transaction-manager="transactionManager"/> </beans> |
引入部分如下:
【made by siwuxie095】
SSH框架分模块开发的更多相关文章
- MAVEN day04 SSH之分模块开发
一.创建父工程 1.选择>>"Maven Project"创建Maven工程.并且选择Packaging为 POM. 创建父工程主要是让子工程区继承父工程,减少冗余,多 ...
- Maven02——回顾、整合ssh框架、分模块开发、私服
1 回顾 1.1 Maven的好处 节省空间 对jar包做了统一管理 依赖管理 一键构建 可跨平台 应用在大型项目可提高开发效率 1.2 Maven安装部署配置 1.3 Maven的仓库 本地仓库 远 ...
- java使用maven项目(二)分模块开发
1 整合ssh框架 1.1 依赖传递 只添加了一个struts2-core依赖,发现项目中出现了很多jar, 这种情况 叫 依赖传递 1.2 依赖版本冲突的解决 1. 第 ...
- 项目:《ssh框架综合项目开发视频》-视频目录和第六天的EasyUI简单讲解
4 练习使用技术: Struts2 + hibernate5.x + spring4.x + mysql数据库 1 crm:customer relational manager,客户关系管理 2 c ...
- Spring_day04--HibernateTemplate介绍_整合其他方式_Spring分模块开发
HibernateTemplate介绍 1 HibernateTemplate对hibernate框架进行封装, 直接调用HibernateTemplate里面的方法实现功能 2 HibernateT ...
- Struts2_day01--Struts2的核心配置文件_常量配置_分模块开发_Action编写方式
Struts2的核心配置文件 1 名称和位置固定的 2 在配置文件中主要三个标签 package.action.result,标签里面的属性 标签package 1 类似于代码包,区别不同的actio ...
- ssm集成(maven)& 分模块开发--详细教程
1 maven版本的ssm 1.1 最简单的版本步骤: (1) 创建maven web项目 (2) 在pom.xml中导入依赖的jar包 (3) 再写配置文件: web.xml <!DOCTYP ...
- Struts2分模块开发
-------------------siwuxie095 Struts2 分模块开发 在实际开发中,如果一个项目是团队开发的,也就是很多人开发的, 每个人都需要去修改 struts.xml,因为 s ...
- spring+springmvc+hibernate架构、maven分模块开发样例小项目案例
maven分模块开发样例小项目案例 spring+springmvc+hibernate架构 以用户管理做測试,分dao,sevices,web层,分模块开发測试!因时间关系.仅仅測查询成功.其它的准 ...
随机推荐
- 邮件服务器fixpost服务(1)
发邮件所用的协议,SMTP协议,端口TCP25 收邮件所用的协议,pop3.imap协议 邮件客户端(MUA):foxmail.闪电邮.邮件大师.outlook 搭建邮件服务器所用到的软件(MTA邮件 ...
- OSPF里几个特殊区域(stub、Totally stubby、NSSA、Totally NSSA)总结
网友总结: 简单的说,就是 stub过滤4,5类lsa,ABR会产生缺省的3类lsa,区域内不能引入外部路由 total stub过滤3,4,5类lsa,ABR会产生缺省的3类lsa,区域内不能引入外 ...
- Unreal Engine 4 性能优化工具(Profiler Tool)
转自:http://aigo.iteye.com/blog/2296548 Profiler Tool Reference https://docs.unrealengine.com/latest/I ...
- tensorflow函数学习:队列和线程
队列函数: FIFOQueue和RandomShuffleQueue 1.FIFOQueue FIFOQueue是先进先出队列,主要针对序列样本.如:使用循环神经网络时,需要处理语音.文字.视频等序列 ...
- CGLib缺少jar出现 java.lang.ClassNotFoundException: org.objectweb.asm.Type
CGLib实现动态代理区别于JDK动态代理,不需要目标类实现任何接口,是通过生成代理类子类的方式,而且据说速度要快于JDK动态代理.所以我想要试验一下CGlib的动态代理,网上找了些例子,自己动手写了 ...
- windows下面安装easy_install和pip教程
方便安装whl:安装完成后,可以使用pip install xxx.whl 安装一个python轮子 python扩展库的路径:Python\Python36\Lib\site-packages\ ...
- linux 下各个4K区块文件大小测试速度对比 机械硬盘性能 64K性价比收益最高
机械硬盘,每个区块取三次数最小值为准,带2G RAM缓存卡 4K3.4 MB/秒 8K7.3 MB/秒 16K9.5 MB/秒 32K16.7 MB/秒 64K44.2 MB/秒 128K67.1 M ...
- Ubuntu下mysql的卸载重装
注:该方法是彻底删除ubuntu下面的文件,然后重新安装,更新root密码,所以mysql原数据会被删掉,所以一定一定要记得备份!!!!!!!! 转自:http://blog.csdn.net/chu ...
- html大小写问题
js中变量名,函数,关键字都区分大小写,如var i;和var I;是两个不同的变量. css中定义的元素名称不区分大小写的. html中,标签和标签属性统一使用小写形式,固有属性也一律使用小写,自定 ...
- python学习之RabbitMQ-----消息队列
RabbitMQ队列 首先我们在讲rabbitMQ之前我们要说一下python里的queue:二者干的事情是一样的,都是队列,用于传递消息 在python的queue中有两个一个是线程queue,一个 ...