Spring的配置文件

来源:互联网 发布:和晟实业投资 知乎 编辑:程序博客网 时间:2024/06/08 19:14
<?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: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/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"><!-- Spring框架管理Service,mapper对象 -->    <context:component-scan base-package="com.yue.ssm">        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>    </context:component-scan>    <!-- 加载外部属性资源文件 -->    <context:property-placeholder location="classpath:/jdbc.properties"/>    <!-- C3P0数据源 -->    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">        <property name="driverClass" value="${jdbc.driverClass}"/>        <property name="jdbcUrl" value="${jdbc.jdbcUrl}"/>        <property name="user" value="${jdbc.user}"/>        <property name="password" value="${jdbc.password}"/>    </bean>    <!-- Spring要管理MyBatis框架的核心对象:SqlSessionFactory -->    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">        <property name="dataSource" ref="dataSource"/>        <property name="configLocation" value="classpath:/mybatis-config.xml"/>        <property name="typeAliasesPackage" value="com.yue.ssm.bean"/>        <property name="mapperLocations">            <list>                <value>classpath*:/config/mybatis/*Mapper.xml</value>            </list>        </property>    </bean>    <!-- 设置扫描Mapper接口及映射配置 -->    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">        <property name="basePackage" value="com.yue.ssm.mapper"/>    </bean>    <!-- 事务管理器:切面类 -->    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">        <property name="dataSource" ref="dataSource"/>    </bean>    <!-- 声明式事务 -->    <aop:config>        <aop:pointcut expression="execution(public * com.yue.ssm.service.*Service.*(..))" id="txPointcut"/>        <aop:advisor advice-ref="txAdviceId" pointcut-ref="txPointcut"/>    </aop:config>    <tx:advice id="txAdviceId" transaction-manager="transactionManager">        <tx:attributes>            <tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT" rollback-for="java.lang.Exception" timeout="5"/>            <tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT" rollback-for="java.lang.Exception" timeout="5"/>            <tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT" rollback-for="java.lang.Exception" timeout="5"/>            <tx:method name="query*" read-only="true"/>            <tx:method name="get*" read-only="true"/>            <tx:method name="*" read-only="true"/>        </tx:attributes>    </tx:advice></beans>

原创粉丝点击