Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is systemProperties in Spring and where to find it?

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.

like image 666
Mukhamedali Zhadigerov Avatar asked Aug 24 '18 10:08

Mukhamedali Zhadigerov


People also ask

How do I find system properties?

How do I open System Properties? Press Windows key + Pause on the keyboard. Or, right-click the This PC application (in Windows 10) or My Computer (previous versions of Windows), and select Properties.

Where are system properties stored in Java?

properties file located in users->appdata->locallow->sun->java>deployment and also directly putting key=value in runtime parameter in java control panel but not working.

How do I find system properties in Linux?

1. How to View Linux System Information. To know only the system name, you can use the uname command without any switch that will print system information or the uname -s command will print the kernel name of your system. To view your network hostname, use the '-n' switch with the uname command as shown.

How do you define system properties?

The System class maintains a Properties object that describes the configuration of the current working environment. System properties include information about the current user, the current version of the Java runtime, and the character used to separate components of a file path name.


2 Answers

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

like image 57
Dinesh Avatar answered Oct 17 '22 11:10

Dinesh


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

like image 5
Piotr Rogowski Avatar answered Oct 17 '22 11:10

Piotr Rogowski