Spring JavaConfig Reference Guide

Rod Johnson

Costin Leau

Chris Beams

Spring Java Configuration

Version 1.0.0.M4

Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.

November 2008

Table of Contents

1. Introduction
1.1. What this guide covers
1.1.1. Topics not covered
1.2. What JavaConfig requires to run
1.3. Where to get support
1.4. Where to follow development
1.5. How to retrieve and build JavaConfig from source
1.6. How to import JavaConfig as an Eclipse project
1.7. How to obtain milestone builds
1.7.1. Via manual download
1.7.2. Via Maven
1.7.3. Via Ivy
1.8. How to obtain nightly (aka 'snapshot') builds
1.8.1. Via manual download
1.8.2. Via Maven
1.8.3. Via Ivy
2. Authoring @Configuration classes
2.1. @Configuration
2.2. @Bean
2.2.1. Declaring a bean
2.2.2. Injecting dependencies
2.2.3. Receiving lifecycle callbacks Using JSR-250 annotations Using Spring interfaces Using @Bean initMethodName / destroyMethodName attributes
2.2.4. Using *Aware interfaces
2.2.5. Specifying bean scope Using @Bean's scope attribute @ScopedProxy Lookup method injection
2.2.6. Customizing bean naming
2.2.7. Working with Spring FactoryBean implementations
3. Using @Configuration classes
3.1. Bootstrapping applications with JavaConfigApplicationContext
3.1.1. Construction Options Construction by class literal Construction by base package Post-construction configuration
3.1.2. Accessing beans with getBean() Type-safe access String-based access
3.2. Bootstrapping web applications with JavaConfigWebApplicationContext
4. Modularizing configurations
4.1. Partitioning bean definitions into multiple @Configuration classes
4.2. Referencing beans across @Configuration classes
4.2.1. Direct bean references with @Autowired
4.2.2. Fully-qualified bean references with @Autowired
4.3. Aggregating @Configuration classes with @Import
4.4. ConfigurationSupport
5. Working with externalized values
5.1. @ExternalValue
5.1.1. @ExternalValue fields
5.1.2. @ExternalValue methods
5.2. Available ValueSource annotations
6. Combining configuration styles
6.1. JavaConfig and XML
6.1.1. Bootstrapping JavaConfig from XML with ConfigurationPostProcessor Configuring configurations
6.1.2. Bootstrapping XML from JavaConfig with @ImportXml
6.2. JavaConfig and Annotation-Driven Configuration
6.2.1. @AnnotationDrivenConfig
6.2.2. @ComponentScan
7. Transaction-management support
7.1. @AnnotationDrivenTx
8. AOP support
8.1. @AspectJAutoProxy
8.1.1. @Aspect-annotated @Configuration classes
9. JMX support
9.1. @MBeanExport
10. Testing support
10.1. JavaConfigContextLoader
11. Extending JavaConfig
11.1. @Plugin