駒風少年 2021-10-08 08:59 采纳率: 50%
浏览 708
已结题

Could not resolve placeholder 'jdbc.driver' in value "${jdbc.driver}"

代码

img

<beans xmlns="


xmlns:xsi="
xmlns: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:database.properties"/>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${jdbc.driver}"/>
    <property name="jdbcUrl" value="${jdbc.url}"/>
    <property name="user" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" value="dataSource"/>
    <!--   绑定mybatis的配置文件     -->
    <property name="configLocation" value="mybatis-config.xml"/>
</bean>
<!-- 4.配置dao接口扫描包,动态实现了Dao接口可以注入到Spring容器中!   -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    <property name="basePackage" value="com.kuang.dao"/>
</bean>

问题:at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'jdbc.driver' in value "${jdbc.driver}"

展开全部

  • 写回答

2条回答 默认 最新

  • CSDN专家-微编程 2021-10-08 09:18
    关注

    为什么不使用阿里的连接池?另外你的连接配置是不是有问题,前面需要加jdbc.吗?你的database.properties里面的key难道是类似jdbc.driver吗?如果key是类似driver=xxx的,配置文件里的变量就不是jdbc.driver而是driver

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
    駒風少年 2021-10-09 02:04

    用阿里的连接池也是同样的问题,database.properties里面的key 是driver=xxx,但是去掉了jdbc以后还是出现错误:Cannot convert value of type 'java.lang.String' to required type 'javax.sql.DataSource' for property 'dataSource': no matching editors or conversion strategy found。

    回复
    CSDN专家-微编程 回复 駒風少年 2021-10-09 02:13

    你没有发现吗,报错信息不一样了,接下来就是

    <property name="dataSource" value="dataSource">
    配置错了,这写法Spring会以字符串方式注入,报类型不匹配异常,改为
    <property name="dataSource" ref="dataSource"/>
    

    回复
    駒風少年 回复 CSDN专家-微编程 2021-10-09 02:22

    嗯,我这个我已经发现了修改了,但是又出现了了另外的问题:Caused by: org.apache.ibatis.exceptions.PersistenceException:

    Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

    The error may exist in com/kuang/dao/bookMapper.xml

    The error may involve com.kuang.dao.bookMapper.queryAllBook

    The error occurred while executing a query

    Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)
    ... 33 more
    

    要上手太难了

    回复
    展开全部17条评论
查看更多回答(1条)
编辑
预览

报告相同问题?

问题事件

  • 系统已结题 10月16日
  • 已采纳回答 10月9日
  • 创建了问题 10月8日
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部