I have inherited the following java code, that gets the value of a property from a properties file: The intended behavior in the above flow is that personName will either be retrieved from the properties file or will be returned as null if its not there, and handled accordingly. However when the property is n…
Tag: properties
How can i fetch property from application-test.properties file in Java class?
I have set the variable “spring.profiles.active” in my environment to “test” and I have below file in my src/main/resources. application-test.properties It has one property “machine” I want to access this property in one of my Java based class. PropertiesConfig class: But w…
Connecting Spring boot application with postgresql problem with properties
I wanted to connect my application from spring boot with postgresql running in docker I am doing everything according to this tutorial – https://www.youtube.com/watch?v=8fbfHu8isI4&t=1452s , but I keep getting the same error: Error starting ApplicationContext. To display the conditions report re-run…
Spring PropertySourcesPlaceholderConfigurer beans: resolve property value at runtime
I am loading properties with multiple PropertySourcesPlaceholderConfigurer beans and setting placeholder prefix-es: While I can inject a property value by specifying it’s index and key like this: Sometimes I need to determine the value of the prefix (‘foo’) at runtime and dynamically resolve…
Spring choose property source by a combination of profiles
I have multiple environments driven by Spring profiles, such as application-int.yml, application-dev.yml etc with similar content: application-int.yml application-dev.yml My goal is to use the following property based on both the environment name and whether the mock profile is included: ws.endpoint from appl…
How write path to file properties?
I wrote a program with two language. I created a file resources_in.properties. When I attempted to get properties from the file, I got the error: Exception in thread “main” java.lang.NullPointerException at java.util.Properties$LineReader.readLine(Properties.java:434) at java.util.Properties.load0…
Throw exception when a property is duplicated in a properties file
How can I throw an Exception when a properties file contains a duplicate property? Here is an example demonstrating this situation: Answer I suppose you are reading the file with something like Properties.load(). It sets the parameter internally using put(key, value). You can override that method to get the d…
The Properties.load would close the InputStream?
I saw this example, and I didn’t see the close() method invoked on the InputStream, so would prop.load() close the stream automatically? Or is there a bug in the example? Answer The Stream is not closed after Properties.load () The above code returns “-1” so the stream is not closed. Otherwi…
Open a file’s properties window using Java
This is a question only regarding Java in Windows. I need a method that will call this window: So essentially the method should be something like: So the statement: opernProperties(new File(test.txt)); should open the above window. So just to clarify, I do not want to read and manage the properties. I just wa…
In Java -D what does the D stand for?
What does the D in Set a system property value. Of the Java application launcher stand for? For some reason it’s been bothering me, why D? Answer I’ve always assumed it was to define the value of a property… possibly a legacy from C compilers, which often use -D as similar to #define in code…