SPRING CONCEPTS

Spring Framework

Spring Concepts / Spring Framework

Spring Framework helps you connect selected Java objects and build features such as web request handling.

Understand the idea

You write a TodoService class with a constructor that needs a TodoStore. Spring can obtain a store object, pass that reference into the service constructor, and keep the resulting service ready for other objects to use. The application contains many objects; only those registered with Spring are beans.

A concrete example

TodoStore store = new TodoStore();
TodoService service = new TodoService(store);

// This is ordinary Java construction and constructor injection.
// Spring can manage these objects using configured bean definitions.

In the application

All three applications use Spring-managed controllers, services, configuration, and repositories.

Spring Framework, Spring MVC, and Spring Boot are related layers. They have different responsibilities.

Class versus object

A class defines a type. new TodoStore() constructs one instance. A variable holds a reference to it. A class is not automatically instantiated just because it exists in the project. Static methods do not require an instance of their declaring class; abstract classes and interfaces cannot be directly instantiated.

What does Spring manage?

Usually shared working objects such as controllers, services, repositories and configured helpers. It does not automatically create one bean for every class, nor make every Todo data item a bean. The application is a running program containing many objects, not one large object.

Watch one dependency being supplied

Illustrative configuration excerpt
@Bean
public TodoService todoService(TodoStore store) {
    return new TodoService(store);
}

Spring supplies the store parameter from the context. The method calls the constructor. Spring registers the returned service and supplies it wherever that bean is needed. Dependency means an object this service needs to do its work.

Construction first, method calls later

Two different stages
Startup: store object -> service constructor -> printer constructor
Later: printer.print() -> service.titles() -> store.findAll()

Your classes implement the work. Spring manages their configured construction, connections and lifecycle. The main Spring Foundation section includes a complete downloadable example and expected output.

What do IoC, DI and bean mean?

Dependency injection means supplying the required collaborator; ordinary new TodoService(store) already does this through the constructor.

Inversion of Control describes moving responsibility for managing configured object construction from your application code to the container.

A bean is an object registered with and managed by that container. Default singleton scope reuses one instance per bean definition per context; it does not mean all objects are shared beans.

Detailed walkthrough: How Spring creates and connects objects →

Related concepts

Read the official documentation ↗
Java 21 · Spring Boot 4.1.1 · Edupoly