Spring2 Hibernate3 J

2023-01-31 03:01:23 Spring2 Hibernate3
<1>、applicationContext.xml

<?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:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/beans [url]http://www.springframework.org/schema/beans/spring-beans-2.0.xsd[/url]
            [url]http://www.springframework.org/schema/jee[/url] [url]http://www.springframework.org/schema/jee/spring-jee-2.0.xsd[/url]">
 
    <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName">
            <value>com.Mysql.jdbc.Driver</value>
        </property>
        <property name="url">
            <value>jdbc:mysql://192.168.3.110:3306/DBName?useUnicode=true&characterEncoding=GBK</value>
        </property>
        <property name="username">
            <value>root</value>
        </property>
        <property name="passWord">
            <value>root</value>
        </property>
    </bean>
 
    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory"
        class="org.springframework.ORM.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref local="dataSource" />
        </property>
        <property name="mappingResources">
            <list>
                <value>com/xh/hibernate/vo/User.hbm.xml</value>
            </list>
        </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">create</prop>
                -->
            </props>
        </property>
    </bean>
 
    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref local="sessionFactory" />
        </property>
    </bean>
 
    <!-- Add DAOs here -->
    <bean id="userDAO"
        class="com.xh.hibernate.dao.impl.UserDAOImpl">
        <property name="sessionFactory">
            <ref local="sessionFactory" />
        </property>
    </bean>
 
    <!-- Add Managers here -->
    <bean id="userManagerTarget"
        class="com.xh.spring.service.impl.UserManagerImpl">
        <property name="userDAO">
            <ref local="userDAO" />
        </property>
    </bean>
 
    <bean id="userManager"
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="transactionManager">
            <ref local="transactionManager" />
        </property>
        <property name="target">
            <ref local="userManagerTarget" />
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="save*">PROPAGATION_REQUIRED</prop>
                <prop key="remove*">PROPAGATION_REQUIRED</prop>
                <prop key="update*">PROPAGATION_REQUIRED</prop>
                <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
            </props>
        </property>
    </bean>
 
</beans>

相关文章