美文网首页
ssm:spring.xml例

ssm:spring.xml例

作者: 何以解君愁 | 来源:发表于2022-09-19 08:23 被阅读0次
    <?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"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool.xsd">
    
    <!--    扫描组件,控制层除外-->
        <context:component-scan base-package="com">
            <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        </context:component-scan>
    
    <!--    引入-->
        <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
    <!--    配置数据源-->
        <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
            <property name="driverClassName" value="${jdbc.driver}"></property>
            <property name="url" value="${jdbc.url}"></property>
            <property name="username" value="${jdbc.username}"></property>
            <property name="password" value="${jdbc.password}"></property>
        </bean>
    
    <!--    配置事务管理器-->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"></property>
        </bean>
    <!--开启事务注解驱动-->
        <tx:annotation-driven transaction-manager="transactionManager"/>
    <!--    配置sqlSessionFactoryBean,可直接在Spring的IOC获取-->
        <bean class="org.mybatis.spring.SqlSessionFactoryBean">
    <!--        设置核心配置文件路径-->
            <property name="configLocation" value="classpath:mybatis-config.xml"></property>
    <!--        设置数据源-->
            <property name="dataSource" ref="dataSource"></property>
    <!--        设置类型别名的包-->
            <property name="typeAliasesPackage" value="com.Pojo"></property>
    <!--        设置映射文件路径只有映射文件的包与mapper接口的包不一致时才可设置-->
    <!--        <property name="mapperLocations" value="classpath:resources下的包名/*.xml"></property>-->
        </bean>
    
    <!--    配置mapper接口的扫描,可以将指定包下的所有mapper接口通过SqlSession创建代理实现类对象,并将这些对象交给IOC容器管理-->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="com.Mapper"></property>
        </bean>
    </beans>

    相关文章

      网友评论

          本文标题:ssm:spring.xml例

          本文链接:https://www.haomeiwen.com/subject/xgyportx.html