Java Reference
In-Depth Information
package com.apress.springenterpriserecipes.spring3.javaconfig;
import static java.lang.System.*;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
public class LawFirmConfiguration {
private Attorney denny;
private Attorney alan;
private Attorney shirley;
public LawFirm bostonLegal() {
LawFirm lawFirm = new LawFirm();
Arrays.asList(denny, alan, shirley));
return lawFirm;
This functionality is often overkill for defining simpler beans. For example, if you want to simply let
Spring instantiate the bean, and you don't have anything to contribute to that process, you can either
write an @Bean method, or you can fall back and configure it in XML. Which you do is up to you, as a
matter of taste. If it were an object specific to my application, I'd handle it in the Java configuration, but
I would leave Spring's many FactoryBean implementations inside the XML where they could be made
quick work of or you could benefit from some of the schemas.
This chapter reviewed some of the major new features in Spring 3.0. You learned how to obtain the
framework and how to include it in your application. The new Spring Expression Language (SpEL) was
highlighted. It will be useful in the web tier as well as for your everyday configuration needs. You learned
how to use Spring's TaskExecutor support to isolate your code from the platform's local thread pool
implementation and inconsistencies. Finally, you were shown how to configure applications with a
minimal of XML, relying instead on the JavaConfig option.
The next chapter will review working with data access in Spring, including JDBC access, ORM
solutions (such as Hibernate and JPA), and more.
Search WWH ::

Custom Search