SSH整合配置applicationContext.xml/hibernate.cfg.xml/struts.xml

SSH整合时Spring中的applicationContext.xml 配置,本人在这里的Bean使用自动扫描与装配;使用注解方式管理事务;并且把Hibernate中的数据源信息放在了这里。

另外把JDBC的数据连接信息单独放在了一个名叫 jdbc.properties 中,然后引用外部文件$方法调用;(这样有利于未来更换数据库时只要单独修改jdbc.properties即可)


1.以下为struts.xmll配置

<?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.devMode" value="true"></constant>
	<!-- 设置扩展名 -->
	<constant name="struts.action.extension" value="com"></constant>
	<!-- Action包块 -->
	
	<package name="default" namespace="/" extends="struts-default">
	
		<action name="user" class="userAction" >
			<result></result>
		</action>
	</package>
    <!-- Add packages here -->

</struts>


2.以下为hibernate.cfg.xml配置

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

	<!-- 方言 -->
	<property name="dialect">
		org.hibernate.dialect.MySQL5InnoDBDialect
	</property>

	<!-- 显示SQL语句 -->
	<property name="show_sql">true</property>

	<!-- 自动建表 -->
	<property name="hbm2ddl.auto">update</property>

	<!-- 导入映射文件 -->
	<mapping resource="com/qzh/entity/User.hbm.xml" />


</session-factory>

</hibernate-configuration>


3.以下为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: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-2.5.xsd
				http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
				http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

	<!-- 自动扫描与装配 -->
	<context:component-scan base-package="com.qzh.oa"></context:component-scan>
	<!-- 引用外部文件 -->
	<context:property-placeholder location="classpath:jdbc.properties"/>
	<!-- 数据源dataSource -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass"     value="${driverClass}">    </property>
		<property name="jdbcUrl" 	 value="${jdbcUrl}">	    </property>
		<property name="user" 		 value="${user}">	    </property>
		<property name="password"	 value="${password}">  	    </property>
		<!-- 其他配置 -->
			<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
			<property name="initialPoolSize" value="3"></property>
			<!--连接池中保留的最小连接数。Default: 3 -->
			<property name="minPoolSize" value="3"></property>
			<!--连接池中保留的最大连接数。Default: 15 -->
			<property name="maxPoolSize" value="5"></property>
			<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
			<property name="acquireIncrement" value="3"></property>
			<!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->
			<property name="maxStatements" value="8"></property>
			<!-- maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->
			<property name="maxStatementsPerConnection" value="5"></property>
			<!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
			<property name="maxIdleTime" value="1800"></property>    
	</bean>
	<!-- SessionFactory配置 -->
		<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
			<property name="dataSource" ref="dataSource"></property>
			<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
		</bean>
	<!-- 事务管理 -->
	<tx:annotation-driven transaction-manager="transactionManager"/>
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
</beans>


4.整合使用到的JAR包

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类
XML入门的常见问题(二)
Java对象的强、软、弱和虚引用
JS解析XML文件和XML字符串详解
java中枚举的详细使用介绍
了解Xml格式
XML入门的常见问题(四)
深入SQLite多线程的使用总结详解
PlayFramework完整实现一个APP(一)
XML和YAML的使用方法
XML轻松学习总节篇