Spring Boot and MVC: IoC, Beans, Validation, HTTP

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/86

encourage image

There's no tags or description

Looks like no tags are added yet.

87 Terms

1
New cards

What is Inversion of Control (IoC)?

A principle where Spring controls object creation, wiring, and lifecycle instead of application code.

2
New cards

What is an IoC container?

The Spring component that creates, configures, wires, and manages beans.

3
New cards

What is Dependency Injection (DI)?

Supplying an object with dependencies from outside rather than constructing them inside the object.

4
New cards

How do IoC and DI relate?

IoC is the principle; DI is a common way Spring implements it.

5
New cards

What are the three DI types?

Constructor injection, setter injection, and field injection.

6
New cards

How do constructor and setter injection differ?

Constructor injection sets required dependencies at creation; setter injection supplies them afterward.

7
New cards

Why is field injection less recommended?

It hides dependencies and complicates unit testing and immutability.

8
New cards

Which DI type is preferred for required dependencies?

Constructor injection: explicit dependencies, easy testing, and final fields.

9
New cards

What does @Autowired do?

Requests that Spring resolve and inject a matching bean.

10
New cards

What is @Qualifier used for?

Selecting a specific bean when multiple candidates have the same type.

11
New cards

What does @Primary do?

Marks the preferred bean when several candidates match.

12
New cards

What is a Spring bean?

An object created, configured, and managed by the Spring IoC container.

13
New cards

What is component scanning?

Spring discovers annotated components in selected packages and registers them as beans.

14
New cards

What does @ComponentScan control?

The packages Spring scans to find annotated classes and register beans.

15
New cards

Which annotations mark Spring components?

@Component, @Service, @Repository, and @Controller; @RestController is also a component.

16
New cards

What are the basic bean lifecycle stages?

Instantiate → inject dependencies → initialize → use → destroy.

17
New cards

What does @PostConstruct do?

Runs an initialization method after dependencies are injected.

18
New cards

What does @PreDestroy do?

Runs cleanup before a managed bean is destroyed; not automatically for prototype beans.

19
New cards

What is singleton bean scope?

One bean instance per bean definition within one Spring container; the default.

20
New cards

What is prototype bean scope?

A new instance whenever that bean is requested from the container.

21
New cards

What are the web bean scopes?

Request, session, application, and WebSocket scopes.

22
New cards

Request scope vs session scope?

Request creates one bean per HTTP request; session uses one per HTTP session.

23
New cards

What does @Bean do?

Registers the return value of a configuration method as a Spring-managed bean.

24
New cards

What does @Configuration do?

Marks a class containing bean definitions and application configuration.

25
New cards

What is Spring Initializr?

A tool that generates Spring Boot projects with build files, dependencies, and an entry point.

26
New cards

Which build tools can Spring Initializr use?

Maven or Gradle.

27
New cards

What is a Spring Boot starter?

A curated dependency bundle for a feature such as web, JPA, or security.

28
New cards

What does @SpringBootApplication combine?

@SpringBootConfiguration, @EnableAutoConfiguration, and @ComponentScan.

29
New cards

What is Spring Boot Actuator?

A module exposing operational endpoints for health, metrics, and management.

30
New cards

What does /actuator/health show?

Application health status, commonly UP or DOWN.

31
New cards

What do /actuator/info and /actuator/metrics do?

Info shows configured app information; metrics exposes measurements.

32
New cards

Why secure Actuator endpoints?

Some endpoints reveal sensitive application and operational details.

33
New cards

What do HTTP status categories 1xx-5xx mean?

1xx information; 2xx success; 3xx redirection; 4xx client error; 5xx server error.

34
New cards

What do 200, 201, and 204 mean?

200 OK; 201 Created; 204 No Content.

35
New cards

What do 400, 401, 403, and 404 mean?

400 Bad Request; 401 Unauthorized; 403 Forbidden; 404 Not Found.

36
New cards

What does 500 mean?

Internal Server Error.

37
New cards

What do HTTP 301 and 302 mean?

301 Moved Permanently; 302 Found (temporary redirection).

38
New cards

How do you set a status code in a controller?

Use ResponseEntity.status(HttpStatus.CREATED).body(value), or @ResponseStatus.

39
New cards

What does @Valid do on an endpoint parameter?

Triggers Bean Validation on the supplied object, such as @Valid @RequestBody UserDto dto.

40
New cards

What happens when request-body validation fails?

Spring MVC typically returns 400 Bad Request for invalid @Valid request bodies.

41
New cards

What is @NotNull vs @NotEmpty vs @NotBlank?

@NotNull rejects null; @NotEmpty rejects null/empty; @NotBlank also rejects whitespace-only text.

42
New cards

What does @Size do?

Sets minimum and maximum length or size for supported values.

43
New cards

What do @Email, @Min, @Max, and @Pattern do?

Validate email format, numeric bounds, and regex pattern, respectively.

44
New cards

What is @RestController?

A controller whose handler return values are written directly to HTTP response bodies, often as JSON.

45
New cards

How does @RestController differ from @Controller?

@RestController includes @ResponseBody; @Controller can return view names.

46
New cards

What is @RequestMapping?

Defines a URL mapping and can constrain HTTP methods and other request conditions.

47
New cards

What are the five specialized HTTP mapping annotations?

@GetMapping, @PostMapping, @PutMapping, @PatchMapping, @DeleteMapping.

48
New cards

What are GET, POST, PUT, PATCH, DELETE commonly used for?

Retrieve, create, replace, partially update, and delete resources.

49
New cards

What do @PathVariable, @RequestParam, @RequestBody do?

Bind URL path parts, query parameters, and request body data to method arguments.

50
New cards

What is Spring MVC?

Spring's web framework for HTTP request handling using Model-View-Controller and DispatcherServlet.

51
New cards

What does DispatcherServlet do in Spring MVC?

Acts as the front controller, dispatching HTTP requests to handlers.

52
New cards

What is ORM?

Object-Relational Mapping links Java objects and fields to relational tables and columns.

53
New cards

What is Hibernate?

A Java ORM framework that maps entities and performs persistence operations.

54
New cards

What are Hibernate benefits?

Less JDBC boilerplate, object mapping, caching, and database dialect support.

55
New cards

How do JPA and Hibernate relate?

JPA is a persistence specification; Hibernate is an implementation of it.

56
New cards

What does @Entity do?

Marks a class as a persistent entity mapped to a database table.

57
New cards

What does @Id do?

Identifies an entity's primary-key field.

58
New cards

What does @GeneratedValue do?

Configures how an entity primary-key value is generated.

59
New cards

How do Spring Data and Hibernate differ?

Spring Data offers repository abstractions; Hibernate performs ORM and persistence.

60
New cards

What is JpaRepository vs CrudRepository?

CrudRepository offers core CRUD; JpaRepository adds JPA-focused methods and paging/sorting inheritance.

61
New cards

What is a derived query method in Spring Data JPA?

A repository method such as findByEmail() whose name defines a query.

62
New cards

What is JPQL?

JPA-standard query language that queries entities and their properties.

63
New cards

What is HQL?

Hibernate Query Language: entity-based queries with Hibernate-specific features.

64
New cards

What is native SQL?

Direct SQL targeting physical database tables and columns.

65
New cards

What is the Criteria API?

A Java API for constructing type-aware, dynamic entity queries programmatically.

66
New cards

What does @Transactional do?

Defines a Spring-managed transaction boundary for commit and rollback.

67
New cards

What does ACID stand for?

Atomicity, Consistency, Isolation, Durability: key transaction properties.

68
New cards

What is the default @Transactional propagation?

REQUIRED: join an existing transaction or create one if none exists.

69
New cards

How does REQUIRES_NEW differ from REQUIRED?

REQUIRES_NEW suspends an existing transaction and starts an independent one.

70
New cards

What does NESTED propagation do?

Creates a nested transaction using a savepoint when supported.

71
New cards

What do SUPPORTS and MANDATORY mean?

SUPPORTS uses a transaction if present; MANDATORY fails if none exists.

72
New cards

What do NOT_SUPPORTED and NEVER mean?

NOT_SUPPORTED runs without a transaction; NEVER fails if one exists.

73
New cards

When does @Transactional roll back by default?

Normally on unchecked RuntimeException and Error, not ordinary checked exceptions.

74
New cards

What is transaction isolation?

Rules governing how concurrent transactions see each other's database changes.

75
New cards

What is Spring Security?

A framework for authentication and authorization of Spring applications.

76
New cards

What is authentication vs authorization?

Authentication verifies identity; authorization determines allowed actions.

77
New cards

What is SecurityConfig?

A conventional configuration class defining security beans and access rules, such as SecurityFilterChain.

78
New cards

What is CORS?

Cross-Origin Resource Sharing: browser rules for accessing responses from another origin.

79
New cards

What is UserDetailsService?

A Spring Security interface that loads user information through loadUserByUsername().

80
New cards

What is UserDetailsManager?

Extends UserDetailsService with operations to create, update, and delete users.

81
New cards

What is RBAC?

Role-Based Access Control: permissions granted through roles such as USER or ADMIN.

82
New cards

How can Spring Security restrict an endpoint to admins?

Use an authorization rule such as hasRole("ADMIN") for the endpoint.

83
New cards

What is @RestControllerAdvice?

Global advice for REST controllers, including centralized exception handling and response bodies.

84
New cards

How does @ControllerAdvice differ from @RestControllerAdvice?

@RestControllerAdvice includes @ResponseBody, suitable for REST error responses.

85
New cards

What is @ExceptionHandler?

Marks a method to handle specified exception types thrown during request processing.

86
New cards

How do @RestControllerAdvice and @ExceptionHandler work together?

The advice class applies globally; @ExceptionHandler chooses exceptions and returns a suitable HTTP response.

87
New cards

What status might a missing resource exception return?

404 Not Found, often set with ResponseEntity or @ResponseStatus in an exception handler.