#Spring configuration with external file

11 messages · Page 1 of 1 (latest)

brisk rock
#

Hello. I can't seem to figure out how app configuration in Spring works.
I have a file app_config.json contained somewhere within the machine's filesystem. I have to get the path to that file from the environment var APP_CONFIG_FILE. I also want to have a similar copy of that file inside the project, which should be default when APP_CONFIG_FILE isn't defined or empty. I want to read the json from file and parse it into class AppConfiguration and have it accessible with DI.
The thing is I can't figure out where to start. The more articles i read, the more confused i become. So any help (some advice or examples) would be much appreciated!

merry raptorBOT
#

This post has been reserved for your question.

Hey @brisk rock! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

inland hatch
#

I mean, Spring provides solutions, and you're essentially responding, "no, we'll use my thing instead, even though it doesn't provide any sort of benefits, I just like it better"
Spring most likely allows this anyway, but it is to be expected that only core Spring developers would know how, considering it doesn't have any real use

brisk rock
#

It's just that i have the same logic implemented for another service in asp.net. I just thought it would be easier to get started with what i had prior. What would be the better way?

inland hatch
#

standardization. Use a .properties or .yaml file, as spring configuration examples provide.
But, again, it's most likely doable the way you want. It's just, nobody is going to publish tutorials for what could be useful to you and to nobody else

brisk rock
#

Okay, but can i do it the Spring way but with a json file? I really don't want to change the file because other service use it.

inland hatch
#

Like I said, most likely. It's just, there is nothing surprising about how it's hell to find information on how to do it

#

In fact, worse coming to worst, you could probably handle it all in the public static void main before starting spring engine

brisk rock
#

Okay I'll keep looking for solutions, thanks

merry raptorBOT
# brisk rock Okay I'll keep looking for solutions, thanks

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.