zoukankan      html  css  js  c++  java
  • Spring的配置文件 (SSM maven项目)

    <?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: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.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/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
    
        <!--Spring的配置文件  这里主要是配置和业务逻辑有关的-->
    
    
        <context:component-scan base-package="xyz.sun">
            <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"></context:exclude-filter>
        </context:component-scan>
    
        <!-- 数据源  事务控制器  xxx...-->
        <context:property-placeholder location="classpath:dbconfig.properties" />
    
    
        <bean id="pooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
            <property name="driverClass" value="${jdbc.driverClass}"></property>
            <property name="user" value="${jdbc.user}"></property>
            <property name="password" value="${jdbc.password}"></property>
    
        </bean>
    
    
        <!--==============================配置和mybatis整合====================================== -->
        <bean id="SqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
            <!--指定mybatis 全局配置文件的位置-->
            <property name="configLocation" value="classpath:mybatis-config.xml"></property>
            <property name="dataSource" ref="pooledDataSource"></property>
            <!--指定mybatis  mapper文件 的位置-->
            <property name="mapperLocations" value="classpath:mapper/*.xml"></property>
        </bean>
    
        <!--配置扫描器  将mybatis 接口的实现 加入到 ioc容器中-->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <!--扫描所有dao接口的实现, 加入到ioc容器中-->
            <property name="basePackage" value="xyz.sun.crud.dao"></property>
        </bean>
    
    
    
    
        <!--=====================事务控制的配置======================-->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <!--控制住数据源-->
            <property name="dataSource" ref="pooledDataSource"></property>
        </bean>
    
        <!--开启基于注解的事务,  也可以使用xml配置形式事务(必要主要的都是使用配置)-->
        <aop:config>
            <!-- 切入点表达式-->
            <aop:pointcut  expression="execution(* xyz.sun.crud.service..*(..))" id="txPoint" />
            <!--配置事务增强 -->
            <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint" />
        </aop:config>
        <!--配置事务增强 事务如何切入 -->
         <!-- 配置事务属性 -->
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <!--代表素偶有方法都是事务方法-->
                <tx:method name="*" />
                <!--以get 开始的所有方法-->
                <tx:method name="get*" read-only="true" />
            </tx:attributes>
        </tx:advice>
    
        <!--Spring 配置文件的核心点 (数据源、与mybatis的整合 事务控制)-->
    </beans>
    jdbc.jdbcUrl=jdbc:mysql://localhost:3306/ssm_crud?useUnicode=true&characterEncoding=utf8&useSSL=true
    jdbc.driverClass=com.mysql.jdbc.Driver
    jdbc.user=root
    jdbc.password=123456

    截图:

  • 相关阅读:
    mysql批量导入删除
    sql查重去除id最小值
    Rest构建分布式 SpringCloud微服务架构项目
    Django模板语言及视图
    Django模板语言
    面向对象进阶
    初识面向对象
    os模块和sys模块
    random模
    时间模块
  • 原文地址:https://www.cnblogs.com/mzdljgz/p/11143297.html
Copyright © 2011-2022 走看看