Java.lang.NumberFormatException:For input string: "${jdbc.maxactive}"

Source: Internet
Author: User

First, the question

Using SPRINGMVC and MyBatis integration, the JDBC configuration is isolated out of the time of the following error, Baidu has not found a solution for a long time, go home Google, find a solution, have to say that Google is strong, not nonsense, the following is a specific error:

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.L Ang. 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) ... Morecaused By:org.springframework.beans.typemismatchexception:Failed to convert property value of type [java.lang.String] to required type [Int.] for property ' maxactive '; nested ex Ception 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) ...  Morecaused 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) ... More
Ii. Causes of Occurrence

The problem is that the placeholder is not recognized, that is, the $ {jdbc.maxactive} is treated as a string directly during the loading process. Myabatis using Mapperscannerconfigurer scan mode, he will take precedence over propertyplaceholderconfigurer execution, so this time, ${jdbc.maxactive} has not been replaced by the value inside the properties file, it appears typemismatchexception, and then it is abnormal.

Third, the solution
    <!--Configure Sqlsessionfactory -    <BeanID= "Mysqlsessionfactory"class= "Org.mybatis.spring.SqlSessionFactoryBean">        < Propertyname= "DataSource"ref= "Mysqldatasource" />         < Propertyname= "Configlocation"value= "/web-inf/classes/config/db/mybatis-config.xml" />        < Propertyname= "Mapperlocations">            <List>                <value>Classpath:com/xsjt/dao/**/*mapper.xml</value>            </List>        </ Property>    </Bean>     <!--The DAO interface contains the package name, and spring automatically finds the class under it -     <Beanname= "Mysqlmapperscannerconfigurer"class= "Org.mybatis.spring.mapper.MapperScannerConfigurer">        < Propertyname= "Annotationclass"value= "Org.springframework.stereotype.Repository" />        < Propertyname= "Basepackage"value= "Com.rxwx.dao" />        <!--here with Sqlsessionfactorybeanname instead of sqlsessionfactory, and then using value instead of ref -        < Propertyname= "Sqlsessionfactorybeanname"value= "Mastersqlsessionfactory" />    </Bean>

Mapperscannerconfigurer Scan DAO's configuration to use Sqlsessionfactorybeanname instead of sqlsessionfactory, then use value instead of ref.

Java.lang.NumberFormatException:For input string: "${jdbc.maxactive}"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.