Tag: property placeholder

Spring @Value TypeMismatchException:无法将类型’java.lang.String’的值转换为必需类型’java.lang.Double’

我想使用@Value注释来注入Double属性,例如: @Service public class MyService { @Value(“${item.priceFactor}”) private Double priceFactor = 0.1; // … 并使用Spring属性占位符(属性文件): item.priceFactor=0.1 我得到例外: org.springframework.beans.TypeMismatchException:无法将类型’java.lang.String’的值转换为必需类型’java.lang.Double’; 嵌套exception是java.lang.NumberFormatException:对于输入字符串:“$ {item.priceFactor}” 有没有办法使用来自属性文件的Double值?