Configuration class,
@Configuration
public class SpringContext {
@Bean
public BlockingQueue<String> queue(@Value("${queue.size}") int queueSize) {
return new LinkedBlockingQueue<>();
}
}
Main class,
@SpringBootApplication
public class SpringContextTest {
public static void main(String[] args) {
final SpringApplication springApplication = new SpringApplication(SpringContext.class);
springApplication.setWebEnvironment(false);
springApplication.run();
System.out.println("queue.size" + System.getProperty("queue.size"));
}
}
application.yml,
queue.size: 10
While starting the main class I'm getting the following error,
Caused by: java.lang.NumberFormatException: For input string: "${queue.size}"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_144]
I'm I missing some annotations ?, In my understanding I've used the minimal annotations required for a spring boot application. I have seen some similar posts but didn't helped. Also tried with --spring.config.location.
My Spring starter version: 1.3.6.RELEASE
Your config file looks more like an application.properties
rather than an application.yml
queue.size: 10
The equivalent yml
should be:
queue:
size: 10
UPDATE
Yes both should work in .yml
you are right. I replicated exactly your example and it worked!
Just make sure you application.yml
file is in the root of the src/main/resources/
. I had the same error as yours when I had the application.yml
file in a subdirectory e.g. src/main/resources/com/myapp/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With