What is systemProperties in Spring and where to find it?
Asked Answered
S

2

9

I'm reading Spring In Action book and there's is an example:

public BlankDisc(@Value("#{systemProperties['disc.title']}" String title){
}

But what is systemProperties here and where to declare it? I thought it was application.properties file and added disc.title=Beatles there. But the value of title variable is null when the bean is created. I can inject the value of disc.title if i use @Value("${disc.title}") by the way.

Seism answered 24/8, 2018 at 10:20 Comment(1)
SystemProperties here are the normal system properties defined while starting any java process, using -D flag. What you are seeing is just spring shorthand for referencing it.Reduce
S
10

This is the property that will be set while starting the jar like "java -Dproperty.name="value" -jar app.jar"

Sevik answered 24/8, 2018 at 10:29 Comment(1)
Is it possible to refer properties defined in application properties in SPEL?Mcclenaghan
C
6

For example if you run application java -jar app.jar -Dmy.param=myParam

then you can create bean

@Bean
public String myParam(){
   return System.getProperty("my.param");
}

and inject by @Autowiere

Cherry answered 24/8, 2018 at 10:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.