Skip to content
Advertisement

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 while running this as a Spring boot application in Eclipse. I am getting below error: What am I missing?

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 your application with ‘debug’ enabled. 2021-08-02 16:18:56.400 ERROR 4169 — [ main] o.s.b.d.LoggingFailureAnalysisReporter : APPLICATION FAILED TO START Description:

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 the property value. Is this possible? If not, which alternative solutions are recommended for this use case?

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 application-dev.yml for dev profiles ws.endpoint from application-int.yml for int profiles ws.mock from application-dev.yml for dev mock profiles ws.mock from

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(Properties.java:353) at java.util.Properties.load(Properties.java:341) at com.rd.java.basic.practice.Helper.getProper(Part5.java:18) at com.rd.java.basic.practice.Helper.main(Part5.java:27) I think it is because I have an incorrect path to properties. resources_in.properties is located at MyAppsrcmainresources_in.properties. The main class

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 desired behaviour like e.g. EDIT: Integrating this into the OP’s code:

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. Otherwise it should have thrown java.io.IOException: Stream Closed

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 want to open the properties window. Answer I

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. EDIT: The closest I have

Advertisement