SpringSource/spring-scala — pull request #8 by hekonsek (2013-02-23 21:09:40+00:00)
Title: Added AnnotationConfigSupport.

Hi,

I've been browsing through the Spring Scala Jira and spotted issue [1] related to the autowiring support in Spring Scala.

While the author of the issue can just register regular `AutowiredAnnotationBeanPostProcessor` bean in order to use `@Inject` in his beans, this is not in sync with configuration style used in Spring XML.

In XML we would use ``. This is more higher level (aka DSL) approach than registering `AutowiredAnnotationBeanPostProcessor` explicitly in the context. The additional value gained from the `` is that it registers some other useful bean processors and that it uses `AnnotationConfigUtils#registerAnnotationConfigProcessors` under the hood. The usage of `AnnotationConfigUtils` cannot be overemphasized as it guarantees that only single instance of each annotation processor will be registered in the context.

I think that Scala Spring users should get their `` DSL to enable annotation-based configuration as well.

class ConfigWithoutTrait extends FunctionalConfiguration {

annotationConfig = true

bean("foo")(new Foo())

}

For Scala user preferring cake-like [2] configuration style we should provide `AnnotationConfigSupport` trait as well. The latter trait would enable annotation config the same way as `annotationConfig = true` does.

class ConfigWithoutTrait extends FunctionalConfiguration with AnnotationConfigSupport {

bean("foo")(new Foo())

}

I believe that the proposed approach is the Scala-like way to provide this useful functionality to the `FunctionalConfiguration` users while keeping consistent style with the existing Spring XML goodies. What do you think about this idea?

[1] https://jira.springsource.org/browse/SCALA-5
[2] http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di