springmvc学习指南 之---第37篇 记录一下druil连接池配置报错问题

applicationCOntext.xml这个内容为

<?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"
       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">
    <context:property-placeholder location="classpath:db.properties"/>
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">

        <property name="url" value="${abc.url}"/>
        <property name="driverClassName" value="${abc.driver}"/>
        <property name="username" value="${abc.username}"/>
        <property name="password" value="${abc.password}"/>
        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="1" />
        <property name="minIdle" value="1" />
        <property name="maxActive" value="10" />
    </bean>
    <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="typeAliasesPackage" value="com.zyt.po"/>
        <property name="mapperLocations" value="classpath:/mapping/*Mapper.xml"/>
    </bean>
    <!-- 4、定义mapper接口扫描器 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <!-- 扫描所有XxxMapper接口,将接口实例的创建交给spring容器 -->
        <property name="basePackage"
                  value="com.zyt.dao"/>
    </bean>
</beans>
db.properties的内容为
abc.driver=com.mysql.cj.jdbc.Driver
abc.url=jdbc:mysql://localhost:3306/msb_dongbao_test?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
abc.username=root
abc.password=root

进行测试成功的,如果将

配置为

    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">

        <property name="url" value="${url}"/>
        <property name="driverClassName" value="${driver}"/>
        <property name="username" value="${username}"/>
        <property name="password" value="${password}"/>
        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="1" />
        <property name="minIdle" value="1" />
        <property name="maxActive" value="10" />
    </bean>

看样子好像是username没识别出来,但是为什么呢? 想不通 

posted @ 2021-12-04 19:46  张艳涛&java  阅读(39)  评论(0编辑  收藏  举报