ssh整合之六管理我们的配置文件
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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://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>
这样的话,我们就把配置文件分门别类了,到时候再修改或查看时就一目了然了!
ssh整合之六管理我们的配置文件的更多相关文章
- 三大框架 之 SSH整合
目录 SSH整合 Spring整合web项目 在Servlet当中直接加载配置文件,获取对象 存在问题 解决方案 SSH整合 引入Jar包 引入配置文件 创建包结构 创建相关类 创建Customer业 ...
- ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存
ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存 hibernate : Hibernate是一个持久层框架,经常访问物理数据库 ...
- 三大框架SSH整合
三大框架SSH整合 -------------------------------Spring整合Hibernate------------------------------- 一.为什么要整合Hi ...
- 【Java EE 学习 67 下】【OA项目练习】【SSH整合JBPM工作流】【JBPM项目实战】
一.SSH整合JBPM JBPM基础见http://www.cnblogs.com/kuangdaoyizhimei/p/4981551.html 现在将要实现SSH和JBPM的整合. 1.添加jar ...
- SSH整合(struts2.3.24+hibernate3.6.10+spring4.3.2+mysql5.5+myeclipse8.5+tomcat6+jdk1.6)
终于开始了ssh的整合,虽然现在比较推崇的是,ssm(springmvc+spring+mybatis)这种框架搭配确实比ssh有吸引力,因为一方面springmvc本身就是遵循spring标准,所以 ...
- SSH整合之spring整合hibernate
SSH整合要导入的jar包: MySQL中创建数据库 create database ssh_db; ssh_db 一.spring整合hibernate带有配置文件hibernate.cfg.xml ...
- 【转载】Ssh整合开发介绍和简单的登入案例实现
Ssh整合开发介绍和简单的登入案例实现 Ssh整合开发介绍和简单的登入案例实现 一 介绍: Ssh是strtus2-2.3.1.2+ spring-2.5.6+hibernate-3.6.8整合的开 ...
- SSH整合,applicationContext.xml中配置hibernate映射文件问题
今天在applicationContext.xml中配置sessionFactory时遇到了各种头疼的问题,现在总结一下: 1.<property name="mappingDirec ...
- SSH整合方案2
[案例3]SSH整合_方案2 ** 案例描述 两个知识点的演示 其一,SSH整合的第二个方案 其二,Spring+JDBC+Struts2 参考代码 31) 使用工程spring4 32 ...
随机推荐
- asp.net中http接口的开发
第一篇博客,如有不足请大家多多谅解. 最近一段时间主导着一个app的开发.所有功能都交给后台接口进行处理.采用http,传输的数据类型为json. http接口是一种基于基于TCP.http服务的ap ...
- Intellij +Maven 报错: Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match.
在intellij使用 Maven Project 测试时,运行test时看到log里的报错信息: -Dmaven.multiModuleProjectDirectory system propert ...
- 深度剖析PHP序列化和反序列化
序列化 序列化格式 在PHP中,序列化用于存储或传递 PHP 的值的过程中,同时不丢失其类型和结构. 序列化函数原型如下: string serialize ( mixed $value ) 先看下面 ...
- MYSQL汇总
一.1.1 MYSQL 一.1.1.1 基础特性 1)性能卓越,服务稳定,很少出现异常宕机: 2)开放源代码且无版权制约,自主性强,使用成本低: 3)历史悠久,社区及用户非常活跃,遇到问题,可快速获得 ...
- webpack.config.js文件的高级配置
一.多个入口文件之前我们配置的都是 一个入口 var webpack = require('webpack'); var commonsPlugin = new webpack.optimize.Co ...
- svn 发布脚本整合
svn提交时出现(413 Request Entity Too Large)错误解决方法 在nginx的server配置中增加 client_max_body_size 100M; linux多实例a ...
- 从源码来看ReentrantLock和ReentrantReadWriteLock
上一篇花了点时间将同步器看了一下,心中对锁的概念更加明确了一点,知道我们所使用到的锁是怎么样获取同步状态的,我们也写了一个自定义同步组件Mutex,讲到了它其实就是一个简版的ReentrantLock ...
- vs运行单个cpp文件
打开vs,新建项目,左侧win32见上图,右侧 win32控制台应用程序,填好名称后,确定----下一步,如下图,空项目 紧接着如下图,通过现有项添加自己的cpp文件,便可以运行了
- GLES2学习VBO和VAO的使用
在GLES2中使用VBO和VAO对象,已经简单vs,ps绘制一个三角形. 1. 初始化操作代码,创建VBO.VAO,编译和链接shader program. void DebugApplication ...
- Leetcode 3——Palindrome Number(回文数)
Problem: Determine whether an integer is a palindrome. Do this without extra space. 简单的回文数,大一肯定有要求写过 ...