Managing beans in the JavaConfig container
The JavaConfig
approach provides an easier, straightforward and programmatical way of loading beans to the container. This approach uses annotations and classes to manage the lifespan of the objects, the dependencies, and the injection of values and objects to setters and constructors. The next recipe showcases how to construct and utilize a Java-based ApplicationContext
container.
Getting started
Let us create and use the ch02-jc
project to create our first annotation-based ApplicationContext
container. We will be using the same model classes presented in the recent recipe.
How to do it...
Let us create beans inside a JavaConfig's context definition class:
- Inside the
ch02-jc\src\main\java
directory, create a package:org.packt.starter.ioc.model
. Implement the sameEmployee
andDepartment
model classes as in the previous recipe, Managing the beans in a XML-based container recipe. OpenBeanConfig
context definition class and inject these newly created...