黑马程序员技术交流社区

标题: spring配置文件模版 [打印本页]

作者: hy2014051202    时间: 2017-6-15 10:47
标题: 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:tx="http://www.springframework.org/schema/tx"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd">

        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
                <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
                <property name="jdbcUrl" value="jdbc:mysql:///test"></property>
                <property name="user" value="root"></property>
                <property name="password" value="root"></property>
        </bean>

        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
                <property name="dataSource" ref="dataSource"></property>
        </bean>
        <tx:annotation-driven transaction-manager="transactionManager" />

        <bean id="userService" class="com.test.service.UserService">
                <property name="userDao" ref="userDao"></property>
        </bean>
        <bean id="userDao" class="com.test.dao.UserDao">
                <property name="jdbcTemplate" ref="jdbcTemplate"></property>
        </bean>




        <bean id="transactionManager"
                class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
                <property name="dataSource" ref="dataSource"></property>
        </bean>

        <tx:advice id="txAdice" transaction-manager="transactionManager">

                <tx:attributes>

                        <tx:method name="accountMoney" />
                </tx:attributes>
        </tx:advice>

        <aop:config>
                <aop:pointcut expression="execution(* com.test.service.OrederService.*(..))"
                        id="pointcut1" />
                <aop:advisor advice-ref="txAdice" pointcut-ref="pointcut1" />

        </aop:config>







欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2