Skip to main content

Posts

Showing posts with the label spring

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...

Spring TestContext Framework

I'm somewhat surprised that there hasn't been more noise around in the blogosphere about Spring 2.1 's TestContext Framework . I had the pleasure of working with Juergen Hoeller for a day after JavaZone. Among other things, I learned about the fancy @Autowired annotation that you can use to make your autowiring much safer. Normally autowiring is considered bad practice, but it was Juergen's advice that now it is okay to use. This means in practice that all your service beans will still be declared in an applicationContext.xml file, but the dependencies and object graphs will be annotated in the Java files (or atleast where you see fit). After this I had a deeper look into the features of Spring 2.1. Note the point about "our next-generation Spring TestContext Framework with support for JUnit4". Now this is cool. Why we need it (or something like it) For a long while I (and many of my colleagues and peers) have been annoyed by the disability to manage tests a...