jeff porter jeff porter - 13 days ago 6
Java Question

Spring propertyConfigurer not working

I've got the following problem that it seems that the injection properties from the propertyConfigurer is not working.

The error I get is...

Caused by: java.lang.NumberFormatException: For input string: "${db.maxactive}"
at java.lang.NumberFormatException.forInputString(
at java.lang.Integer.parseInt(
at java.lang.Integer.valueOf(
at org.springframework.util.NumberUtils.parseNumber(
at org.springframework.beans.propertyeditors.CustomNumberEditor.setAsText(
at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(
at org.springframework.beans.TypeConverterDelegate.doConvertValue(
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(

From the stacktrace it is trying to inject the value "${db.maxactive}" into the dbcp driver.
If I turn up the logging I can see the following (this is the stacktrace when I don't inject that property)...

[INFO] Refreshing startup date [Thu Jun 27 08:58:08 BST 2013]; root of context hierarchy
[INFO] Loading XML bean definitions from class path resource [conf/spring/applicationContext-StandAlone.xml]
[INFO] Loading XML bean definitions from class path resource [conf/spring/applicationContext-monitoring.xml]
[INFO] Loading XML bean definitions from class path resource [conf/spring/dataAccessContext-local.xml]
[INFO] Loading XML bean definitions from class path resource [conf/spring/applicationContext-jdbc.xml]
[INFO] Loading XML bean definitions from class path resource [conf/spring/applicationContext-beans.xml]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/porterj/.m2/repository/org/slf4j/slf4j-jdk14/1.6.1/slf4j-jdk14-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/porterj/.m2/repository/org/slf4j/slf4j-nop/1.6.1/slf4j-nop-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See for an explanation.

**** The exception is thrown HERE, before the is loaded.
[INFO] Loading properties file from class path resource []

This make me think the propertyConfigurer is loaded after it is trying to inject the value, hence its injecting the parameter name, NOT the parameter value.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="false"/>
<property name="locations">

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<property name="maxActive" value="${db.maxactive}"/>

Then my file...

The java class...

ApplicationContext context = new ClassPathXmlApplicationContext("classpath:/applicationContext-StandAlone.xml");

Can someone give me some advice, is this because I'm doing this from a standalone app? I've done this many times in a web app and the propertyConfigurer works fine.

Note: Spring 3.1.2.RELEASE



I've seen this once before in an application that i was developing; I found the problem was something to do with mybatis and there was an issue with the SqlSessionFactoryBean. I didn't dig too deep but if you want to research a bit more start with this link - might be something similar even if you're not using mybatis.

I could see that my beans were getting instantiated and the properties on them set before the Properties had been loaded from the file.

Instead of using a Spring PropertyPlaceholderConfigurer I ended up having to use the spring "util:properties" mechanism to load the properties - once I moved over to this it all started working. Give something like the code below a try - might work for you...

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

  <util:properties id="dataSourceProps" location=""/>

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="#{dataSourceProps['db.driver']}" />
    <property name="url" value="#{dataSourceProps['db.url']}" />
    <property name="username" value="#{dataSourceProps['db.username']}" />
    <property name="password" value="#{dataSourceProps['db.password']}" />
    <property name="maxActive" value="#{dataSourceProps['db.maxactive']}" />