Spring Flashcards

(10 cards)

1
Q

What is the role of the ApplicationContext in Spring?

A

The ApplicationContext is the central interface for configuring and managing a Spring application. Its key roles are:

  1. Bean factory – Creates, configures, and manages the lifecycle of application beans (dependency injection container)
  2. Configuration loading – Reads bean definitions from XML, annotations, or Java config classes
  3. Dependency injection – Wires beans together automatically, resolving dependencies
  4. Resource access – Provides a consistent way to load files and classpath resources
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Clean Architecture emphasises framework independence. Given that Spring Boot is a framework, how can we still apply Clean Architecture principles effectively?

A

Keep Spring at the edges, not in your core.
Structure:

Domain layer – Pure Java classes (entities, business rules). No Spring annotations.
Application layer – Use cases depending only on interfaces and domain objects.
Infrastructure layer – Spring lives here: controllers, @Repository implementations, config.

Key technique: Define interfaces in the inner layers, implement them with Spring in the outer layer.
domain/ → Order.java, OrderRepository (interface)
infrastructure/ → JpaOrderRepository.java (@Repository)
Your business logic stays framework-agnostic and testable. Spring becomes a replaceable plugin rather than the foundation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the role of the Model in the MVC framework

A
  • Represents data and business logic
  • Manages application state
  • UI independent - doesn’t know how data is displayed
  • In spring: entities, repositories and services
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain the role of the View in the MVC framework

A
  • Presents data to the user
  • Renders model state as HTML, JSON, etc.
  • Updates when the model changes
  • In spring: Thymeleaf templates, JSP or JSON responses
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain the role of the controller in the MVC framework

A
  • Intermediary between the model and the view
  • Receives and interprets user input (HTTP requests)
  • Calls the model to fetch/update data
  • Selects appropriate View for the response
    In Spring: @Controller or @RestController classes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain the flow and benefit of the MVC framework

A

User -> Controller -> Model -> Controller -> View -> User

  • Components change independently
  • Enables parallel development
  • Simplifies testing of each layer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Given the following diagram of the Spring Boot flow architecture, explain briefly the meaning of the following terms and how they are implemented in Spring Boot: Repository class

A

Repository class

  • An interface that abstracts database access, typically extending Spring Data interfaces
  • Handles data persistence without exposing database details to the service layer

@Repository
public interface StudentRepository extends JpaRespository<Student, Long>{
Optional<Student> findByEmail(String email);
}</Student>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Given the following diagram of the Spring Boot flow architecture, explain briefly the meaning of the following terms and how they are implemented in Spring Boot: CRUD Services

A

CRUD Services

  • Create, Read, Update, Delete operations provided automatically by extending JpaRepository or CrudRepository.
  • No implementation needed, Spring generates it

```java
repository.save(student);
repository.findById(id);
repository.findAll();
repository.deleteById(id);
~~~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Given the following diagram of the Spring Boot flow architecture, explain briefly the meaning of the following terms and how they are implemented in Spring Boot: Dependency injection and ApplicationContext

A
  • Spring automatically provides dependencies to classes rather than them creating their own.
  • The ApplicationContext is the container that manages all beans and injects them where needed.

```java
@Service
public class StudentService{
private final StudentRepository repository; // Dependency

	@Autowired // Spring injects the repository
	public StudentService(StudentRepository repository){
			this.repository = repository;
	} } ~~~
  • The ApplicationContext creates the StudentRepository bean and injects it into StudentService at startup.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Given the following diagram of the Spring Boot flow architecture, explain briefly the meaning of the following terms and how they are implemented in Spring Boot: Service layer

A
  • Contains business logic, sits between the Controller and Repository. Keeps controllers thin and logic reusable

```java
@Service
public class StudentService{
private final StudentRepository repository;

	public Student registerStudent(String name, String email){
			if(repository.findByEmail(email).isPresent()){
					throw new IllegalArgumentException("Email exists");
			}
			return repository.save(new Student(name,email));
	
	} } ~~~
How well did you know this?
1
Not at all
2
3
4
5
Perfectly