hibernate與spring的配置參考

<?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:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context     
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">


    <!-- DriverMangerDataSource -->
    <bean name="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="oracle.jdbc.OracleDriver"></property>
        <property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl"></property>
        <property name="username" value="wsx"></property>
        <property name="password" value="wsx"></property>
    </bean>

    <bean name="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">false</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
                <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext
                </prop>
            </props>
        </property>

        <property name="mappingLocations">
            <list>
                <value>classpath:com/bean/*.hbm.xml</value>
            </list>
        </property>


    </bean>



    <bean name="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>


    <tx:advice id="basicAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*" propagation="REQUIRED" />
        </tx:attributes>
    </tx:advice>

    <aop:config proxy-target-class="true">
        <aop:pointcut id="basicPoint" expression="execution(* com.service.*.*(..))" />
        <aop:advisor advice-ref="basicAdvice" pointcut-ref="basicPoint" />
    </aop:config>


    <bean name="dictionaryIFC" class="com.service.impl.DictionaryService">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <bean name="noticeService" class="com.service.NoticeService">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean name="mailService" class="com.service.MailService">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
<bean name="surveyService" class="com.service.SurveyService">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
</beans>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章