您的位置:首页 > 编程语言 > Java开发

spring中加入hibernate配置文件

2013-04-25 20:48 423 查看
<?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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: