Spring @Value TypeMismatchException:Failed to convert value of type 'java.lang.String' to required type 'java.lang.Double'

前端 未结 3 1872
没有蜡笔的小新
没有蜡笔的小新 2020-12-14 15:45

I want to use the @Value annotation to inject a Double property such as:

@Service
public class MyService {

    @Value(\"${item.priceFactor}\")
    private D         


        
3条回答
  •  暖寄归人
    2020-12-14 16:05

    How about storing a String and converting to numbers like integers and doubles through getters and setters? For safe code with Java injection you should always use getters and setters and only for other methods in any case. I advice you warmly to read about java security (Which is NOT for hackers), but more for code usage and writing likewise the one you uploaded, wich uses injection.

提交回复
热议问题