简体   繁体   中英

Spring @Value — Failed to convert value of type 'java.lang.String' to required type 'int' [on hold]

In application.yml I have some properties. This is the offending one: waitOnServerDown: 10000

In one of my classes I am trying to grab that value with:

@Value("${config.waitOnServerDown") int waitOnServerDown

At runtime I get the error:

Caused by: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException: For input string: "${config.waitOnServerDown"

This is probably an easy fix, but I'm new to Spring and haven't been able to find the answer with my google-fu.

I did find out how to make it work for objects like Integers:

@Value("#{new Integer('${config.maxPollRecords}')}") Integer maxPollRecords

But in this cause I need waitOnServerDown to be an int.

I was missing a } . I Feel like a fool :( Long day. Thanks for the help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM