application.properties value is not being evaluated correctly across platforms

Viewed 39

In my spring boot batch (2.7.3) application.properties file I have:

rs.input.path=/opt/ingestiondata/rs

Afterthat, when I do a mvn clean install on my windows machine, I get the jar file in my target folder. When I try to do java -jar myjar.jar on my local windows command prompt, it give (as expected, as there is no such path) exception - java.nio.file.NoSuchFileException: \opt\ingestiondata\rs

Then I move the same jar file to the linux box there when I do java -jar myjar.jar my key rs.input.path get evaluated to a windows path - c:\users\ajay\some\dir.

What can be wrong here? As I am using the same jar. Its odd but its what happening since last couple of hours. Tried and verified killall java etc etc and now running out of options. Any pointers/help will be greatly appreciated. Must be something trivial and something horrible I am expecting.

Update: As asked by Abhijit, this is how this is being used.

    @Value("${rs.input.path}")
    private String inputPath;   
    
    @Bean
    ItemReader<File> myReader() throws IOException {
        List<File> files = Files.walk(Paths.get(inputPath))
                            .filter(Files::isRegularFile)
                            .map(Path::toFile)
                            .collect(Collectors.toList());
        return new IteratorItemReader<>(files);
    }
1 Answers

I don't think in a spring application, for any property, there can't be multiple values; unless you are using multiple profile specific 'application.properties' files which are specific to each environment.

Option 1:

"""

Check where your property is residing: 'rs.annual.path=/your/linux/path'

Suppose, let's assume it's inside application-dev.properties

So, you need to select "dev" as Spring profile.

Try running the jar again, by pass passing profile.

(Spring_Property)

  1. java -jar myjar.jar --spring.profiles.active=dev

(Vm_Argument)

2.java -jar -Dspring.profiles.active=dev myjar.jar

"""

Option 2:

"""

Since you are running your jar file inside linux.

Try passing path directly as argument.

(Spring_Property)

  1. java -jar myjar.jar --rs.annual.path=/your/linux/path

You can pass the property as argument. So the Argument-property will taken precedence over Application-property.

"""

Related