Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

As we have seen in the previous section, there are many annotations that can be used to specify a service. Another one is the @Aspect @AspectService annotation. This annotation allows to decorate an existing service in order to add certain "capabilities" to it, like adding a specific caching mechanism to a storage service or implementing logging. Aspects can be plugged to an existing service at runtime, and can also be removed dynamically. This is transparent, and the clients using the existing service are not interrupted, they are just rebound with the aspect service.

As an example, we go back to our SpellChecker application, and we are now looking at the DictionaryAspect class. This class uses the @AspectService annotation in order to add some custom words to an English DictionaryService (with the service property lang=en). The Extra words to add to the English Dictionary will be configured from ConfigAdmin. That's why the class also uses a @ConfigurationDependency annotation:

...