当前位置: 代码迷 >> J2EE >> SSH整合开发的配置有关问题 求教大手 谢了
  详细解决方案

SSH整合开发的配置有关问题 求教大手 谢了

热度:391   发布时间:2016-04-22 02:54:41.0
SSH整合开发的配置问题 求教大手 谢了
最后的配置文件有web.xml applicationcontext.xml以及struts-config.xml
主要想问 hibernate的配置应该是写在applicationcontext.xml里面的对吧??
还有想问配置顺序是怎样的呢
datasource→sessionfactory→。。。接下来就乱了
有没有给一个最基本的applicationcontext.xml配置链接mysql数据库的文件 以及struts-config的基本配置。。

只要最基本的就好 
还有struts-config里面的datasource设置有什么用呢??当applicationcontext配好了 struts里面的数据库配置有必要存在么??
 先感谢各位了
帮忙解惑

------解决方案--------------------
XML code
<?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:p="http://www.springframework.org/schema/p"    xmlns:tx="http://www.springframework.org/schema/tx"    xmlns:context="http://www.springframework.org/schema/context"    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd        http://www.springframework.org/schema/context      http://www.springframework.org/schema/context/spring-context-2.5.xsd">     <!-- 开启组建自动扫描技术,会扫描base-package中所有文件以及其子包的所有文件 --><context:component-scan base-package="service,action"/><!-- 定义数据源,采用默认的单例模式 -->    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">        <property name="driverClassName"  value="com.mysql.jdbc.Driver"/>        <property name="url" value="jdbc:mysql://127.0.0.1:3306/test"/>        <property name="username" value="root"/>        <property name="password" value="root"/>    </bean>    <!-- 定义sessionFactory,采用默认的单例模式 -->    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">        <property name="dataSource" ref="dataSource"/>        <property name="hibernateProperties">            <props>            <!-- 设置方言 -->                <prop key="hibernate.dialect">                    org.hibernate.dialect.MySQLDialect                </prop>            <!-- 格式化输出的sql语句(可选) -->                <prop key="hibernate.format_sql">                    true                </prop>            <!-- 是否打印sql语句 -->            <prop key="hibernate.show_sql">                    false            </prop>                <!-- 配置二级缓存 -->            <prop key="hibernate.cache.use_second_level_cache">                    true            </prop>                <!-- 由于查询的缓存命中率很低,所以我们关掉查询时的二级缓存 -->            <prop key="hibernate.cache.use_query_cache">                    false            </prop>                <!-- 配置二级缓存的相应的类 -->            <prop key="hibernate.cache.provider_class">                    org.hibernate.cache.EhCacheProvider            </prop>                </props>                    </property>        <property name="mappingResources">            <list>                <value>bean/Person.hbm.xml</value>            </list>        </property>    </bean>    <!-- 定义spring事务管理器 --><bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">      <property name="sessionFactory" ref="sessionFactory"/></bean><!-- 将sessionfactory交给spring管理事务 --><tx:annotation-driven transaction-manager="txManager"/></beans>
  相关解决方案