[hotjoe.com] HotJoe Java Help Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Visit java.com
Please send email if you are having login problems - see the posts below for more info.
Hotmail and Yahoo! users - please see the Hotmail post or the Yahoo! post for information on lost emails.
Spring MVC Integration testing: type mismatch from injection from properties file  XML
Forum Index » J2EE Application Development
Author Message
andrew222

Newbie

Joined: 11/22/2009 14:58:13
Messages: 8
Offline

I hope you can help me with a problem I am having with running a Spring integration test using AbstractTransactionalSpringContextTests to wire my dependencies. After everything was wired correctly, I started getting some new errors telling me that some of the values injected read from .properties files were having a type mismatch. When the web application runs. these errors never appear.

This is the error I was getting:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource' defined in class path resource [siebel-test-context.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 'cacheSeconds'; nested exception is java.lang.NumberFormatException: For input string: "${dcla.external.properties.cache.second}"
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [int] for property 'cacheSeconds'; nested exception is java.lang.NumberFormatException: For input string: "${dcla.external.properties.cache.second}"
Caused by: java.lang.NumberFormatException: For input string: "${dcla.external.properties.cache.second}"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.valueOf(Integer.java:547)
at java.lang.Integer.decode(Integer.java:908)
at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:146)
at org.springframework.beans.propertyeditors.CustomNumberEditor.setAsText(CustomNumberEditor.java:114)
at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:343)
at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:319)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:192)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:380)



In a properties file titled 'operations.properties' the value for ${dcla.external.properties.cache.second} is listed as:

dcla.external.properties.cache.second=120


Now, if I hard code the value in the Spring context configuration file, like this

<property name="cacheSeconds" value="120" />

....it will stop complaining about this value and then complain about another value which Spring says it can not convert from Date to String...


When the application runs on it's own, there is no need for a property editor. Can there be something I can do to get these mismatch errors to stop? Is there something I am doing wrong?


stdunbar

Newbie
[Avatar]

Joined: 06/22/2005 14:51:37
Messages: 703
Location: Superior, CO, USA
Online

The error is indicating that Spring isn't substituting the ${} string correctly as it is treating it as a string, not a substitution. Are you confident about the configuration? It's a little hard to tell base on what you've posted but somewhere Spring doesn't know that it should do the substitution.

Thanks for using the forums at hotjoe.com
[WWW] [Yahoo!] [ICQ]
andrew222

Newbie

Joined: 11/22/2009 14:58:13
Messages: 8
Offline


I was able to solve this by eliminating an extra property placeholder configurers and then setting up one property placeholder for all properties files.
 
Forum Index » J2EE Application Development
Go to:   
Powered by JForum 2.1.8 © JForum Team
This site built by Scott Dunbar of Xigole Systems. © 2005-2010 - Scott Dunbar
Java and the Java Get Powered logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.
hotjoe.com and xigole.com have no affiliation with Sun Microsystems, Inc.