views:

138

answers:

5

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?

+1  A: 

I urge you to have a look at Spring. Might seem like overkill for you in the first place, but you wil love it.

Daniel
Spring is already being used to inject instances of the Service and DAO classes. How can it be used for the configuration?
James P.
Use property files and include them. You then have all the properties available as variables which can then be used to be injected in the beans. I didn't do this before myself, but nearly every Spring based framework or app did t like that.
Daniel
+2  A: 

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.

stacker
+2  A: 

If you are working with Spring, take a look at Configuration Placeholders. You can use a simple java properties file for your configuration properties and place it on your class path (or any other location). Alsou you could create your own implementation to use a different form of keeping your configuration values (XML, Database etc.)

Chris
+2  A: 

As configuration is a cross-cutting aspect it doesn't map exclusively to one of these layers. Place the configuration files (XML or properties) into the classpath and use it via Spring to configure your beans.

For properties based configuration data the PropertyPlaceholderConfigurer is a good solution.

Timo Westkämper
+1  A: 

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)

mhaller