spring中加入hibernate配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
 <!-- 加载外部的jdbc配置文件信息 -->
 <bean id ="mappings" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations" value="classpath*:jdbc.properties"></property> 
 </bean>
 <!-- Spring Datasource配置 -->
 <bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource"
  destroy-method="close">
  <property name="driverClassName" value="${jdbc.driverClassName}" />
  <property name="url" value="${jdbc.url}" />
  <property name="username" value="${jdbc.username}" />
  <property name="password" value="${jdbc.password}" />
  <property name="maxActive" value="100" />
  <property name="maxIdle" value="30" />
  <property name="maxWait" value="5000" />
  <property name="defaultAutoCommit" value="true" />
 </bean>
 <!-- 设定hibernate的sessionFactory -->
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource" ref="datasource"></property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">none</prop>
    <prop key="hibernate.format_sql">true</prop>
   </props>
  </property>

<!-- 配置映射文件 -->
   <property name="configLocations">
            <array>
                   <value>classpath*:cn/right.hbm.xml</value>
            </array>
     </property>
      <!-- 以下是物供实体映射的配置文件 -->
     <property name="mappingLocations">
            <list>
                <value>classpath:/cn/entity/*.hbm.xml</value>
                </list>
    </property>
 </bean>

<!-- hibernate Template 配置-->
 <bean id="hibernatetemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>

<!--  加载权限Spring配置文件 -->
 <import resource="classpath*:cn/right-Spring.xml" />

</beans>

posted @ 2013-04-25 20:48  若 ♂ 只如初见  阅读(211)  评论(0编辑  收藏  举报