O'Reilly logo

AspectJ Cookbook by Russ Miles

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

21.4. Managing Application Properties

Problem

You want to manage your applications configuration properties transparently to your applications classes.

Solution

Create an aspect that loads, supplies, monitors, and stores your applications properties.

Discussion

Java application properties are traditionally loaded from and managed by a singleton class. An example of this is the System.getProperty() method, which returns a property supplied to the application from the command line with the -D option.

Unfortunately, singletons tend to be a brittle solution resulting in many areas of your application depending on the interface to the singleton. If the singleton’s interface were to change, it is likely that the many dependent areas of your application would have to change to incorporate the new interface. This is the sort of cross-cutting concern that aspects can solve.

In traditional approaches to property management, the singleton property manager is a passive participant in your application and responds to requests for property information from the various parts of your application. The property manager doesn’t have any knowledge of what is done with the property information it provides, or where it goes, and is dependent on notifications when any property is updated.

With an aspect-oriented approach to system properties, the perspective is switched around. The mechanisms provided by AspectJ allow you to design your property manager so it will actively apply the properties to those areas ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required