1.我们的ssh搭建已经搭建好了,之前是纯xml方式,而且我们的配置文件,是一个框架一个配置文件。这样的话,配置文件中的内容就会很多,这样以后修改起来也会很麻烦,因        此,我们尝试着把这些配置文件引入进来,进行一个分类管理,这样,再修改的话就会方便很多,对于我们快速查阅配置文件也有好处

2.下面我们对之前的配置文件进行改造,先来看看我们的一个大体上的结构,这里我们的hibernate的核心配置文件,即hibernate.cfg.xml,我们是直接交给了spring进行管理

  

  3.这里我们把spring的核心配置文件分开,这样的话,易于维护和查看,最后,我们可以在spring的核心文件中引入其他配置文件即可

  config/spring/applicationContext-customer.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- spring的配置文件:导入约束 -->
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 自定义的java对象交给spring进行管理 --><bean id="customerAction" scope="prototype" class="com.itheima.action.CustomerAction"><property name="customerService" ref="customerService"></property></bean><bean id="customerService" class="com.itheima.service.impl.CustomerServiceImpl"><property name="customerDao" ref="customerDao"></property></bean> <bean id="customerDao" class="com.itheima.dao.impl.CustomerDaoImpl"><property name="hibernateTemplate" ref="hibernateTemplate"></property></bean>
</beans>

  config/spring/applicationContext-jdbc.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- spring的配置文件:导入约束 -->
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!--  第三方的jar包中的java对象交给spring进行管理 --><!--  创建一个hibernateTemplate对象 --><bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate"><!-- 注入sessionFactory --><property name="sessionFactory" ref="sessionFactory"></property></bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"><!-- 配置数据库连接池 --><property name="dataSource" ref="dataSource"></property><!-- hibernate的配置文件 --><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.hbm2ddl.auto">update</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop></props></property><!-- 映射文件 --><property name="mappingLocations" value="classpath:com/itheima/entity/*.hbm.xml"></property></bean>  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"></property><property name="url" value="jdbc:mysql:///ssh_280"></property><property name="username" value="root"></property><property name="password" value="root"></property></bean>
</beans>

  config/spring/applicationContext-tx.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- spring的配置文件:导入约束 -->
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"> <!--配置hibernate的事务管理 --><bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory"></property></bean><!-- 配置事务管理通知 --><tx:advice id="txAdvice"> <tx:attributes><tx:method name="*" propagation="REQUIRED" read-only="false"/><tx:method name="get*" propagation="SUPPORTS" read-only="true"/></tx:attributes></tx:advice><!-- 配置事务的AOP --><aop:config><aop:pointcut expression="execution(* com.itheima.service.impl.*.*(..))" id="pt"/><aop:advisor advice-ref="txAdvice" pointcut-ref="pt"/></aop:config>
</beans>

  applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- spring的配置文件:导入约束 -->
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"> <!--  引入其他的配置文件 --><import resource="classpath:config/spring/applicationContext-customer.xml"/><import resource="classpath:config/spring/applicationContext-jdbc.xml"/><import resource="classpath:config/spring/applicationContext-tx.xml"/>
</beans>

  4.我们的struts也分开管理

  config/struts/struts-customer.xml

<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd">
<struts><package name="customer" extends="struts-default" namespace="/customer"><action name="addCustomerUI" class="customerAction" method="addCustomerUI"><result name="success">/jsp/customer/add.jsp</result></action><action name="getAllCustomer" class="customerAction" method="getAllCustomer"><result name="success">/jsp/customer/list.jsp</result></action></package>
</struts>

  struts的狠心配置文件struts.xml

<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd">
<struts><constant name="devMode" value="true"></constant><!-- 引入其他的struts的动作类配置文件 --> <include file="config/struts/struts-customer.xml"></include>
</struts>

  这样的话,我们就把配置文件分门别类了,到时候再修改或查看时就一目了然了!

  

  

  

转载于:https://www.cnblogs.com/wh-share/p/ssh_spring_hibernate_struts_xml.html

ssh整合之六管理我们的配置文件相关推荐

  1. ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存

    ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存 hibernate  : Hibernate是一个持久层框架,经常访问物理数据库 ...

  2. JavaEE框架整合之基于注解的SSH整合

    基于注解的SSH整合 开发环节步骤: 实体类 -----> DAO开发 -----> Service开发 -----> Action动作类开发 -----> 配置文件(appl ...

  3. 框架学习之Spring 第五节 SSH整合开发[Spring2.5+Hibernate3.3+Struts2]

    1.首先整合Spring和Hibernate ①引入jar包: hibernate核心安装包下的: hibernate3.jar lib\required\*.jar lib\optional\ehc ...

  4. ssh整合学习(1)

    Hibernate框架 1 hibernate核心配置文件 (0)orm思想 -对象关系映射 (1)数据库信息 (2)hibernate信息 (3)映射配置 (4)hibernate核心配置文件 -如 ...

  5. SSH整合,非常详细的SSH整合

    SSH整合,非常详细的SSH整合 这是一个eclipse基于maven整合的struts2-spring-hibernate的简单项目, 1,首先创建一个maven项目如下:名字可以自己命名 , 创建 ...

  6. maven环境下SSH整合

    目录 Maven环境下SSH整合 1 目录结构: 1 1. 导入jar包 2 1.1搭建maven环境 2 1.2配置pom.xml文件 2 1.2.1 pom.xml 2 2. 搭建struts2环 ...

  7. Spring自学教程-ssh整合(六)

    以下是本人原创,如若转载和使用请注明转载地址.本博客信息切勿用于商业,可以个人使用,若喜欢我的博客,请关注我,谢谢!博客地址 感谢您支持我的博客,我的动力是您的支持和关注!如若转载和使用请注明转载地址 ...

  8. 基于Myeclipse的三大框架(SSH)整合

    文中主要基于Myeclipse进行配置,配置流程为:Hibernate --> Spring --> 整合 --> struts2 -->整合.注意:在此文中,主要讲述基于注解 ...

  9. ssh整合步骤之一(搭建环境)

    ssh整合主要可以分为3个步骤:搭建环境.设计架构.实现逻辑 以下是搭建环境的步骤 1.导入jar包 导入ssh基本jar包 2.导入ssh配置文件. 包括(struts.xml hibernate. ...

最新文章

  1. Java--日期的使用
  2. 黑龙江智能车邀请赛中的单车比赛
  3. Redis Cluster深入与实践(续)
  4. JMeter之JMS接口测试
  5. 恰当地利用中间结果集
  6. bzoj1008: [HNOI2008]越狱
  7. 【Python笔记】元组的用法
  8. 桌面虚拟化之盗梦空间
  9. mysql 跨数据库联表查询
  10. 51nod1417 天堂里的游戏
  11. Mybatis-03-配置文件及Mybatis主要API详解
  12. 如何将CAD格式转成可以编辑的矢量图
  13. 怎么才能优雅地向博士导师表达「这周科研没什么进展」?
  14. springcloud @ComponentScan 多模块 扫描其他模块
  15. 【小程序按钮控制视频播放暂停】
  16. 关于轩微电子ADS1256+stm32f103开发板的一点使用小tip
  17. waning rm -i rm -rvfi
  18. 计算机linux二级试题,浙江省计算机等级考试二级考试试题库
  19. 迭代回顾会议咨询记录
  20. poe交换机归类有什么?

热门文章

  1. P2241 统计方形(数据加强版)
  2. 一级域名和二级域名的区别是什么?作用怎样?
  3. MongoDB副本集
  4. 【IOS】获取顶层UIViewController
  5. [zz]lxc使用tc+tbf限制网速
  6. 如何导入nod32企业版的授权文件.lic,并制作镜像服务器?
  7. 域、代理服务、防病毒服务器、WEB/FTP、打印服务器、路由交换、文件服务器
  8. 如何取消button的点击特效_如何衡量一个人的 JavaScript 水平?
  9. ICMP隧道工具ptunnel
  10. Joomla!网站扫描工具joomscan