I had the following problem: it seems that the injection properties of the propertyConfigurer property are not working.
The error I get is ...
Caused by: java.lang.NumberFormatException: For input string: "${db.maxactive}" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:449) at java.lang.Integer.valueOf(Integer.java:554) at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:155) at org.springframework.beans.propertyeditors.CustomNumberEditor.setAsText(CustomNumberEditor.java:115) at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:434) at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:406) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:163) at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:470)
From stacktrace, he tries to enter the value "$ {db.maxactive}" into the dbcp driver. If I turn on logging, I see the following (this is a stacktrace when I do not insert this property) ...
[INFO] Refreshing org .springframework.context.support.ClassPathXmlApplicationContext@ 19bd03e: 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 http:
**** An exception is thrown HERE before jdbc.properties loads. [INFO] Loading a properties file from a class path resource [jdbc.properties]
This makes me think that the Configurer property is loaded after it tries to enter a value, so it enters the parameter name, not the parameter value.
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="ignoreUnresolvablePlaceholders" value="false"/> <property name="locations"> <list> <value>classpath:/jdbc.properties</value> </list> </property> </bean> <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}"/> </bean>
Then my jdbc.properties file ...
db.driver=com.ibm.db2.jcc.DB2Driver db.url=jdbc:db2://dbserver:51000/db db.username=dm db.password=pass db.maxactive=20
Java class ...
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:/applicationContext-StandAlone.xml");
Can someone give me some advice, is it because I am doing this from a standalone application? I have done this many times in a web application, and propertyConfigurer works fine.
Note: Spring 3.1.2.RELEASE
<groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId>