Implementing a Spring container using JavaConfig
Another option for implementing the Spring 5.0 container is through the use of SpringJavaConfig
. This is a technique that uses pure Java classes in configuring the framework's container. This solution eliminates the use of bulky and tedious XML metadata and also provides a type-safe and refactoring-free approach in configuring entities or collections of objects into the container. This recipe will showcase how to create the container using JavaConfig
in a web.xml-less
approach.
Getting started
Create another Maven project using the methodology in Chapter 1, Getting Started with Spring, and name the project ch02-xml
. This STS Eclipse project will be using a Java class approach including its deployment descriptor.
How to do it...
Let us now apply the JavaConfig specification in building the Spring context definition:
- To get rid of the usual Maven bugs, immediately open the
pom.xml
ofch02-jc
and add<properties>
,<dependencies>
, and...