0% found this document useful (0 votes)
0 views

Spring Core Part 1

The document provides an overview of core concepts in the Spring Framework, focusing on the IoC container, bean management, and various features such as validation, data binding, and type conversion. It explains how Spring's IoC container promotes loose coupling through dependency injection and describes the types of resources and beans within the framework. Additionally, it highlights the integration of validation frameworks for user input management and encourages further exploration of Spring concepts in future parts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Spring Core Part 1

The document provides an overview of core concepts in the Spring Framework, focusing on the IoC container, bean management, and various features such as validation, data binding, and type conversion. It explains how Spring's IoC container promotes loose coupling through dependency injection and describes the types of resources and beans within the framework. Additionally, it highlights the integration of validation frameworks for user input management and encourages further exploration of Spring concepts in future parts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Mohammad.mja74@gmail.

com

Spring

Core Concepts

Mohammad Javad Akbari


Senior Java Developer
[email protected]

Introduction
Let’s review Spring core concepts ( part 1 )
we'll take a relaxed tour through key ideas—from how
Spring manages beans with its IoC container to handy
tips on validation, type conversion, and even logging.
Whether you're just starting out or looking for a gentle
refresher, we're here to make learning Spring both
simple and enjoyable.

1. Spring IoC Container and Beans


P1

2. Resources
P1

3. Validation, Data Binding, and Type Conversion


P1

4. Spring Expression Language (SpEL)

5. Aspect-Oriented Programming (AOP)

6. Null-Safety

7. Logging

Mohammad Javad Akbari


Senior Java Developer
[email protected]

IoC Container
Spring IoC Container and Beans

The Spring IoC (Inversion of Control) container is at the


heart of the Spring Framework. It manages the lifecycle
and configuration of application objects (beans) by
instantiating, assembling, and managing them based on
configuration metadata. This approach, known as
dependency injection, promotes loose coupling and
greater modularity in your applications. Essentially, the
container handles the "wiring" of your beans, allowing
developers to focus more on business logic rather than
on the boilerplate code for object management.

You can define a bean using annotations and have


Spring inject it where needed:

Mohammad Javad Akbari


Senior Java Developer
[email protected]

IoC Container
Bean & Constructor injection

Mohammad Javad Akbari


Senior Java Developer
[email protected]

IoC Container
Key Components

What is a Bean exactly?

A Java object managed by the IoC container. Beans are defined via:

@Component, @Service, @Repository, @Controller,

or @Bean (in configuration classes).

What Scopes do beans have?

Singleton (default): One instance per container.

Prototype: New instance per request.

Request/Session/Application: These are Web-aware scopes


(e.g., HTTP request/session).

How can I inject them?

Either via Constructor (recommended) or Setter/Field Injection.

Mohammad Javad Akbari


Senior Java Developer
[email protected]

Resources
What are Resources?

Spring provides a unified abstraction for accessing


different types of resources such as files, classpath
resources, URLs, and more. This abstraction makes it
easier to read configuration files, images, or any other
resource your application might need, regardless of
where they are stored. By using Spring’s resource
loaders, you can write code that is independent of the
underlying resource location, which in turn simplifies
the development process and enhances portability.

Exciting right? so here’s an example that loads a file


from the classpath:

Mohammad Javad Akbari


Senior Java Developer
[email protected]

Resources
Resource Types

Resource Types:

ClassPathResource: Loads resources from the classpath (e.g., src/main/resources).

FileSystemResource: Accesses files from the filesystem.

UrlResource: Reads resources from URLs (e.g., http://, ftp://).

ServletContextResource: Web application resources (e.g., WEB-INF).

Mohammad Javad Akbari


Senior Java Developer
[email protected]

Validation & Binding


Validation, Data Binding, and Type Conversion

Spring offers robust support for validating user input


and binding form data to Java objects. The framework’s
data binding facilities convert input values (often strings
from web forms) to the required target types, leveraging
type conversion mechanisms. In addition, Spring
integrates with validation frameworks (like JSR-303 Bean
Validation) to ensure that the data meets certain
constraints, thereby reducing errors and making it
easier to manage input processing across your
application.

In this example, a simple user object is validated using


JSR-303 annotations, and a controller handles the
binding:
Mohammad Javad Akbari
Senior Java Developer
[email protected]

Validation & Binding


Validation, Data Binding
Easy right? ( JSR-303/JSR-380 Annotations )

Mohammad Javad Akbari


Senior Java Developer
[email protected]

Type Conversion
Type Conversion

Spring Framework's type conversion automatically transforms data between

different types when setting bean properties or handling web request

parameters.

Mohammad Javad Akbari


Senior Java Developer
[email protected]

If you found this helpful, please like


and support, and stay tuned for
Part Two exploring more core
Spring Framework concepts!

Mohammad Javad Akbari


Senior Java Developer

You might also like