一、问题

使用SpringMVC和MyBatis整合,将jdbc配置隔离出来的时候出现下面的错误,百度了很久没有找到解决方法,回家谷歌下,就找到解决方法了,不得不说谷歌就是强大,不废话,下面是具体的错误:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySqlDataSource' defined in ServletContext resource [/WEB-INF/classes/config/spring/daoSource.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [int] for property 'maxActive'; nested exception is java.lang.NumberFormatException: For input string: "${jdbc.maxActive}"
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 41 more
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [int] for property 'maxActive'; nested exception is java.lang.NumberFormatException: For input string: "${jdbc.maxActive}"
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:596)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:603)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:216)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1486)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
... 47 more
Caused by: java.lang.NumberFormatException: For input string: "${jdbc.maxActive}"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:569)
at java.lang.Integer.valueOf(Integer.java:766)
at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:208)
at org.springframework.beans.propertyeditors.CustomNumberEditor.setAsText(CustomNumberEditor.java:113)
at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:468)
at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:441)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:199)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:576)
... 53 more

二、出现原因

  这个问题是无法识别占位符,就是在加载过程中直接把 ${jdbc.maxActive }当做字符串处理了。myabatis使用MapperScannerConfigurer扫描模式后他会优先于PropertyPlaceholderConfigurer执行,所以这个时候,${jdbc.maxActive }还没有被properties文件里面的值所替换,就出现TypeMismatchException,然后就异常了。

三、解决方法

    <!-- 配置sqlSessionFactory -->
<bean id="mysqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="mySqlDataSource" />
<property name="configLocation" value="/WEB-INF/classes/config/db/mybatis-config.xml" />
<property name="mapperLocations">
<list>
<value>classpath:com/xsjt/dao/**/*Mapper.xml</value>
</list>
</property>
</bean> <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean name="mysqlMapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="annotationClass" value="org.springframework.stereotype.Repository" />
<property name="basePackage" value="com.rxwx.dao" />
<!-- 这里 用sqlSessionFactoryBeanName,而不是sqlSessionFactory,接下来用value而不是ref -->
<property name="sqlSessionFactoryBeanName" value="masterSqlSessionFactory" />
</bean>

MapperScannerConfigurer扫描Dao的 配置中要使用sqlSessionFactoryBeanName,而不是sqlSessionFactory,接下来用value而不是ref。

java.lang.NumberFormatException: For input string: "${jdbc.maxActive}"的更多相关文章

  1. mybatis 报错:Caused by: java.lang.NumberFormatException: For input string

    mybatis的if标签之前总是使用是否为空,今天要用到字符串比较的时候遇到了困难,倒腾半天,才在一个论坛上找到解决方法.笔记一下,如下: 转自:https://code.google.com/p/m ...

  2. Mybatis异常:java.lang.NumberFormatException: For input string: "S"

    MyBatis异常日志如下: Caused by: java.lang.NumberFormatException: For input string: "S" at sun.mi ...

  3. Cause: java.lang.NumberFormatException: For input string: "D"

    异常:Cause: java.lang.NumberFormatException: For input string: "D" 问题回显: 原因分析:'D'只有1位,被认为是ch ...

  4. Java——java.lang.NumberFormatException: For input string: ""

    java.lang.NumberFormatException: For input string: "" at java.lang.NumberFormatException.f ...

  5. Swagger2异常 java.lang.NumberFormatException: For input string: ""

    问题在访问swagger首页时报错: java.lang.NumberFormatException: For input string: "" at java.lang.Numb ...

  6. java.lang.NumberFormatException: For input string: " "

    原因:这个异常是说,在将字符串""转换为number的时候格式化错误.额,很简单的异常,以前我是写个方法,然后遍历对比不正确的数字或者用正则表达式之类的.现在发现一个很漂亮的方法, ...

  7. mybatis 参数格式异常-- Error querying database. Cause: java.lang.NumberFormatException: For input string

    mybatis中 <if></if>标签中进行判断时,如果传入的时字符格式和数字进行判断需要将数字进行转译,否则默认是数字和数字进行比较,这是就会出现参数格式异常如<if ...

  8. 可能空字符串转换为浮点型或者整数型:java.lang.NumberFormatException: For input string: " "

    Integer.valueOf(str.equals("")?"0":str)

  9. Window启动Zookeeper报错java.lang.NumberFormatException: For input string:

    用zkServer start命令报如题的错误,改为直接用zkServer启动则ok 还有在window下,myid文件不能是myid.txt,不能带文件格式 dataDir=D:/zookeeper ...

随机推荐

  1. 我对Web开发的认识

    前端 使用mvvm框架,每个视图维护自己的数据模型,更专注于视图模型及状态,在框架的帮助下规范视图与后端的交互及减轻工作量 我的选择是avalon.js 解耦前后端开发 自有资源独立管理,向后端开放资 ...

  2. 在C++中调用DLL中的函数(3)

    1.dll的优点 代码复用是提高软件开发效率的重要途径.一般而言,只要某部分代码具有通用性,就可将它构造成相对独立的功能模块并在之后的项目中重复使用.比较常见的例子是各种应用程序框架,ATL.MFC等 ...

  3. 3ds Max 中的导航控件ViewCube入门介绍

    介绍 ViewCube 3D导航控件提供当前方向的视觉反馈,让用户可以调整视图方向以及在标准视图与等距视图间进行切换. 软件环境:3d Max2015 第一步.启动3d Max软件,打开场景文件 Vi ...

  4. 第三百五十九节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)介绍以及安装

    第三百五十九节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)介绍以及安装 elasticsearch(搜索引擎)介绍 ElasticSearch是一个基于 ...

  5. MyBatis环境配置及入门

    Mybatis 开发环境搭建,选择: MyEclipse8.5 版本,mysql 5.5, jdk 1.8, mybatis3.2.3.jar 包.这些软件工具均可以到各自的官方网站上下载. 整个过程 ...

  6. rrnDB数据库简介-16S基因多拷贝数的证据

    16S基因作为mark gene在微生物群落结构的研究中发挥中重要作用, 但是候选的mark gene 肯定不止16S 一种,最新比较火热的功能基因,也可以作为mark gene.利用功能基因作为ma ...

  7. R语言ggplot2 简介

    ggplot2是一个绘制可视化图形的R包,汲取了R语言基础绘图系统(graphics) 和l attice包的优点,摒弃了相关的缺点,创造出来的一套独立的绘图系统: ggplot2 有以下几个特点: ...

  8. kubeadm init 卡在 Created API client, waiting for the control plane to become ready

    执行 kubeadm init 时出现卡在了 [apiclient] Created API client, waiting for the control plane to become ready ...

  9. http.sys的简单应用

    //public void Run() //{ // //httpListener提供一个简单,可通过编程方式控制的Http协议侦听器.此类不能被继承. // if (!HttpListener.Is ...

  10. ubuntu14.04_64位安装tensorflow-gpu

    第一步(可直接跳到第二步):安装nvidia显卡驱动 linux用户可以通过官方ppa解决安装GPU驱动的问题.使用如下命令添加Graphic Drivers PPA: sudo add-apt-re ...