SpringMVC和Hibernate配置

来源:互联网 发布:中国网络诗歌网为什么 编辑:程序博客网 时间:2024/05/17 07:32
<?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:aop="http://www.springframework.org/schema/aop"
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/aop 
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
  http://www.springframework.org/schema/context   
   http://www.springframework.org/schema/context/spring-context-2.5.xsd
">
<context:component-scan  base-package="com.sxt"/>   
<!-- 支持aop注解 -->
<aop:aspectj-autoproxy />


<bean id="dataSource"  
            class="org.apache.commons.dbcp.BasicDataSource">  
            <property name="driverClassName"  
                value="com.mysql.jdbc.Driver">  
            </property>  
            <property name="url" value="jdbc:mysql://localhost:3306/myhib"></property>  
            <property name="username" value="root"></property>  
            <property name="password" value="123456"></property>
    </bean>  


   <bean id="sessionFactory"  
       class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">  
           <property name="dataSource">  
               <ref bean="dataSource" />  
           </property>
           <property name="hibernateProperties">  
               <props>  
                   <prop key="hibernate.dialect">  
                       org.hibernate.dialect.MySQLDialect  
                   </prop>  
                   <prop key="hibernate.show_sql">true</prop>
                   <prop key="hibernate.hbm2ddl.auto">update</prop>
               </props>
           </property>
<property name="packagesToScan">
<value>com.sxt.po</value>
</property>
   </bean>  


<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" >
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- 配置事务管理 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<aop:config> 
<aop:pointcut expression="execution(public * com.sxt.service.impl.*.*(..))" id="businessService"/> 
<aop:advisor advice-ref="txAdvice" pointcut-ref="businessService" /> 
</aop:config> 
<tx:advice id="txAdvice" transaction-manager="txManager" > 
<tx:attributes> 
<tx:method name="find*"  read-only="true" propagation="NOT_SUPPORTED"  /> 
<tx:method name="*"/>    <!-- 其他方法在实务中运行 --> 
</tx:attributes> 
</tx:advice> 


</beans>
0 0
原创粉丝点击