2 The Spring context: Defining beans

 

This chapter covers

  • Understanding the need for Spring context
  • Adding new object instances to the Spring context

In this chapter, you start learning how to work with a crucial Spring framework element: the context (also known as the application context in a Spring app). Imagine the context as a place in the memory of your app in which we add all the object instances that we want the framework to manage. By default, Spring doesn’t know any of the objects you define in your application. To enable Spring to see your objects, you need to add them to the context. Later in this book we discuss using different capabilities provided by Spring in apps. You’ll learn that plugging in such features is done through the context by adding object instances and establishing relationships among them. Spring uses the instances in the context to connect your app to various functionalities it provides. You’ll learn the basics of the most important features (e.g., transactions, testing, etc.) throughout the book.

Learning what Spring context is and how it works is the first step in learning to use Spring, because without knowing how to manage the Spring context, almost nothing else you’ll learn to do with it will be possible. The context is a complex mechanism that enables Spring to control instances you define. This way, it allows you to use the capabilities the framework offers.

2.1 Creating a Maven project

 
 

2.2 Adding new beans to the Spring context

 
 
 
 

2.2.1 Using the @Bean annotation to add beans into the Spring context

 
 

2.2.2 Using stereotype annotations to add beans to the Spring context

 
 
 
 

2.2.3 Programmatically adding beans to the Spring context

 
 

Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest