0

I think I've read all I could find on the topic, but cannot get the @PropertySource annotation to read an environment variable.

This works fine:

@PropertySource("file:C:\Code\java\myappname\configuration\myappname_config.properties")

But I do need to read the path from environment, so I have the myappname_path environment variable set up (I'm on Windows, with SpringBoot 1.5.4)

Either of those gets me "Could not resolve placeholder" exception:

@PropertySource("file:${myappname_path}\myappname_config.properties") @PropertySource("file:${systemProperties['myappname_path']}\myappname_config.properties")

Thank you very much for help.

UPDATE: OK, that was my fault. Apparently, in this case the reboot was necessary to get the system property to take effect. So now this syntax works: @PropertySource("file:${myappname_path}\myappname_config.properties")

This one does not, but it's not that important: @PropertySource("file:${systemProperties['myappname_path']}\myappname_config.properties")

Thanks a lot for responses.

Nina
  • 21
  • 1
  • 5

1 Answers1

0

This looks like a problem with how you have structured your project. To avoid issues like this I would use an IDE like IntelliJ if you are able to to build out you packages/modules/projects for you.

Generally, .properties files should live inside the /resources folder.

So change where you store that file and it should work. I will write your package directory in yaml format so you can follow:

src:
  main:
    java:
      packagename:
        ... package classes all in here ...
    resources:
      ... property files go here ...
Christien
  • 11
  • 3