Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should configuration be placed?

I have an application structured as follows:

  • dao
  • domain
  • main
  • services
  • utils

I've made a class that reads the application configuration from an XML file. The question is where should it be placed?

By reflex, I'd have placed it in utilities but utility classes have static methods and are stateless whereas this class uses an instance of Apache Commons XMLConfiguration. Should I just adapt the methods so this instance is limited to the scopes of the methods in this class?

like image 342
James P. Avatar asked Dec 28 '22 16:12

James P.


2 Answers

I assume the items are packages, so I'd go with the main package.

  • dao
  • domain
  • main contains the application and its configuration readers
    • config
    • log
  • services
  • utils

Why? The configuration of an application, whether it be in XML or not and whether it is based on an application framework such as Spring or not, is part of its main functionality. Booting up an application is the main responsibility of the application. All the business functionality, all the shiny features it provides are implemented in the domain and service layers.

You're right, utils is all about static or similar tools. As the configuration of an application is very important, I wouldn't declare it a utility. A utility is something which can be easily replaced by another utility of same type (e.g. StringUtil vs. StringUtils vs. IOUtils etc. they all have very similar functionality)

like image 145
mhaller Avatar answered Jan 05 '23 16:01

mhaller


This depends on the build system and application type you use i.g. maven would suggest to place configfiles in src/main/resources

In WAR file you could place them in WEB-INF or WEB-INF/config

According to your project structure I would suggest to introduce a folder config or resources, since almost everybody would expect them there.

like image 39
stacker Avatar answered Jan 05 '23 17:01

stacker