applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       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">
    <!--1.扫描包-->
    <context:component-scan base-package="com.supermark.*"/>
    <!--2.加载属性文件,Spring管理数据源,需要加载配置属性文件-->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <!--加入有属性找不到,也不会报错-->
        <property name="ignoreResourceNotFound" value="true"/>
        <!--要加载的属性文件的位置-->
        <property name="locations">
            <list>
                <value>classpath:jdbc.properties</value>
            </list>
        </property>
    </bean>
    <!--3.SSM框架中 由Spring框架来管理数据源(数据库连接池 德鲁伊)-->
    <bean id="ds" class="com.alibaba.druid.pool.DruidDataSource">
        <!--最基础的一个属性-->
        <property name="driverClassName" value="${jdbcDriver}"/>
        <property name="url" value="${jdbcUrl}"/>
        <property name="username" value="${jdbcUsername}"/>
        <property name="password" value="${jdbcPassword}"/>
    </bean>
    <!--4.MyBatis的session要由Spring来管理-->
    <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!--把配置好的数据源方进入-->
        <property name="dataSource" ref="ds"/>
        <!--加载MyBatis的配置文件,如果MyyBayis配置文件中没有配置内容,此步骤可以省-->
        <property name="configLocation" value="classpath:mybatis-config.xml"/>
        <!--配置Mappper.xml文件所在的位置 -->
        <property name="mapperLocations" value="classpath:mapper/*.xml"/>
        <!--给所有的实体类取别名-->
        <property name="typeAliasesPackage" value="bean"/>
    </bean>
    <!--5.Spring扫描Mappper接口层。在底层用代理的方式生成Mapper接口的代理对象-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="mapper"/>
    </bean>
    <!--6.配置Spring来管理事务,假设不配置-->

</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值