Launching a Spring IoC container

There are two ways to launch a Spring IoC container:

  • BeanFactory
  • ApplicationContext
BeanFactory is the basis for all Spring IoC functionality—the bean life cycle and wiring. The application context is basically a superset of BeanFactory with the additional functionality typically needed in an enterprise context. Spring recommends that you use the application context in all scenarios, except when the additional few KBs of memory that the application context consumes is critical.

Let's use an application context to create a Spring IoC container.

We will use Maven to build our projects. Here are the core Spring JAR files:

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>

We will use Spring BOM to manage the dependency versions. We will discuss Spring BOM further in Chapter 14Spring Best Practices. The snippet for adding it in pom.xml is as follows:

<properties>
<spring.version>5.1.3.RELEASE</spring.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Importing spring-framework-bom in dependencyManagement will ensure that you would not need to specify any version of the Spring versions managed by it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset