Skip to main content

Posts

Showing posts from October, 2007

So you thought Spring's autowiring was a no-no?

Think again. Yet another Spring 2.5 feature, the @Autowired annotation gives you back the control of autowiring, by-type mind. Back in Spring 2.0, autowiring was considered by many to be an anti-pattern due to the lack of control and overview of which beans would actually be injected at runtime. With annotation driven injection (meaning you've got in some Spring XML file), objects are only injected when you explicitly state so. This allows you to reduce the amount of dependency mapping in your Spring XML config files and replace them with annotations in your Java files. If you've got multiple implementations that are possible autowiring candiates, you segment them by using the @Qualifier annotation. Rather than riddle this blog post with snippets of Java and XML, I want you to get the Spring source (you can import it into Eclipse easily) and check out this test: /spring/tiger/test/org/springframework/beans/factory/xml/QualifierAnnotationTests.java I've been playing arou