Spring @Value TypeMismatchException:Failed to convert value of type ‘java.lang.String’ to required type ‘java.lang.Double’
Try changing the following line @Value(“${item.priceFactor}”) to @Value(“#{new Double(‘${item.priceFactor}’)}”)
Try changing the following line @Value(“${item.priceFactor}”) to @Value(“#{new Double(‘${item.priceFactor}’)}”)
Update: For spring 4.2 and higher, no single quotes are needed. Spring will see the first colon as special, and use all the rest as a single string value. For spring 4.2 and higher, @Value(“${prop.url:http://myurl.com}”) For the previous versions, I believe single quotes will do the trick: @Value(“${prop.url:’http://myurl.com’}”)
Just use Spring type ClassPathResource. File file = new ClassPathResource(“countries.xml”).getFile(); As long as this file is somewhere on classpath Spring will find it. This can be src/main/resources during development and testing. In production, it can be current running directory. EDIT: This approach doesn’t work if file is in fat JAR. In such case you need … Read more
I also found the reason @value was not working is, @value requires PropertySourcesPlaceholderConfigurer instead of a PropertyPlaceholderConfigurer. i did the same changes and it worked for me, i am using spring 4.0.3 release. I configured this using below code in my configuration file – @Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); }
Using Spring EL: @Value(“#{‘${my.list.of.strings}’.split(‘,’)}”) private List<String> myList; Assuming your properties file is loaded correctly with the following: my.list.of.strings=ABC,CDE,EFG