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

    <!-- IOC控制反转(Inversion of Control,英文缩写为IoC) -->
    <!-- 把创建对象的权利交给框架,是框架的重要特征, -->
    <!-- 并非面向对象编程的专用术语。 -->
    <!-- 它包括依赖注入(Dependency Injection,简称DI) -->
    <!-- 和依赖查找(Dependency Lookup)。 -->

    <!-- Spring 框架的 AOP(Aspect Oriented Programming) -->
    <!-- Spring 框架的一个关键组件是面向切面的编程(AOP)框架。 -->
    <!-- 面向切面的编程需要把程序逻辑分解成不同的部分称为所谓的关注点。 -->
    <!-- 跨一个应用程序的多个点的功能被称为横切关注点, -->
    <!-- 这些横切关注点在概念上独立于应用程序的业务逻辑。 -->
    <!-- 有各种各样的常见的很好的方面的例子, -->
    <!-- 如日志记录、审计、声明式事务、安全性和缓存等。 -->

    <!-- OOA(Object-Oriented Analysis)面向对象分析 -->
    <!-- OOD(Object-Oriented Design)面向对象设计 -->
    <!-- OOP(Object Oriented Programming)面向对象编程 -->
    <!-- OOP基本原则:程序是由单个能够起到子程序作用的单元或对象组合而成 -->
    <!-- 在OOP中,关键单元模块度是类,而在 AOP中单元模块度是方面。 -->

    <!-- Spring AOP 模块提供拦截器来拦截一个应用程序, -->
    <!-- 例如,当执行一个方法时,你可以在方法执行之前或之后添加额外的功能。 -->
<!--     <context:annotation-config> -->
<!--     <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation" />  -->
    
<!--     </context:annotation-config> -->
<context:component-scan base-package="com.mml.crm2.*.service" >
<!--    <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/> -->
   <!-- 拦截所有的在service层使用 @service注解的类  主要是为了层级更加清晰以及避免注解乱用-->
<!--    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> -->
</context:component-scan>
    <context:property-placeholder location="classpath:jdbc.properties" />
<!--     <import resource="spring-quartz.xml"/> -->
<!--     <import resource="task.xml"/> -->
    <bean id="dataSource2"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${driver}"></property>
        <property name="url" value="${url}"></property>
        <property name="username" value="${user}"></property>
        <property name="password" value="${pass}"></property>
    </bean>
<!--     <bean id="dataSource2" class="com.mchange.v2.c3p0.ComboPooledDataSource"> -->
<!--         <property name="driverClass" value="${driver}"></property> -->
<!--         <property name="jdbcUrl" value="${url}"></property> -->
<!--         <property name="user" value="${user}"></property> -->
<!--         <property name="password" value="${pass}"></property> -->
<!--         <property name="minPoolSize" value="${minPoolSize}"></property> -->
<!--         <property name="maxPoolSize" value="${maxPoolSize}"></property> -->
<!--         <property name="initialPoolSize" value="${initialPoolSize}"></property> -->
<!--     </bean> -->
    <bean id="jdbcTemplate2" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource2"></property>
    </bean>
<!--     <bean id="dao" class="dao.StudentDao"> -->
    
<!--     </bean> -->
<!--     <bean id="service1" class="service.StudentService" /> -->

    <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource2"></property>
        <property name="configLocation" value="classpath:mybatis-config.xml"></property>
    </bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.mml.crm2.*.mapper"></property>
    </bean>
        <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="104857600" />
        <property name="maxInMemorySize" value="4096" />
        <property name="defaultEncoding" value="UTF-8"></property>
    </bean>
    <!-- 配置事务管理器 -->
    <bean
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
        id="transactionManager">
        <property name="dataSource" ref="dataSource2"></property>
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
    <tx:advice id="advice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*" propagation="REQUIRED" />  <!--  *是对所有方法都加-->
<!--             <tx:method name="insert*" propagation="REQUIRED"></tx:method> -->
<!--             <tx:method name="delete*" propagation="REQUIRED"></tx:method> -->
        </tx:attributes>
    </tx:advice>
<!--     用切点把事务切进去 -->
    <aop:config>
        <aop:pointcut expression="execution(* com.mml.crm2.job.controller..*.*(..))"
            id="pointcut" />
        <aop:advisor advice-ref="advice" pointcut-ref="pointcut" />
    </aop:config>

</beans>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值