`

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"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">
   <!-- 配置数据源-->
   <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="username" value="scott"></property>
      <property name="password" value="admin" ></property>
      <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:lgf" />
      <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
   </bean> 
   <!-- 配置hibernate本地会话工厂-->
   <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
      <property name="dataSource" ref="dataSource"></property><property name="mappingLocations" value="classpath:com/code/entity/*.hbm.xml" />
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
         </props>
      </property>
   </bean>
   <!-- 配置hibernate事务管理-->
   <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
      <property name="sessionFactory" ref="sessionFactory"/>
      <property name="dataSource" ref="dataSource"/>
   </bean>
   <!-- 配置事务通知-->
   <tx:advice transaction-manager="transactionManager" id="tx_advice">
      <tx:attributes>
         <tx:method name="get*" read-only="true"/>
         <tx:method name="*"/>
      </tx:attributes>
   </tx:advice>
   <!-- 配置执行的方法表达式,切入点-->
   <aop:config>
      <aop:pointcut expression="execution(* com.ssh.service.*.*(..))" id="tx_pointcut"/>
      <aop:advisor advice-ref="tx_advice" pointcut-ref="tx_pointcut"/>
   </aop:config>
</beans>
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics