Spring Boot Fundamentals: DI, Beans, Configuration, and JPA

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

1/255

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 8:53 PM on 10/18/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

256 Terms

1
New cards

What is Spring?

A Java framework used to build web applications, APIs, and enterprise applications. Its major value is coordinating application objects and integrating web, persistence, security, and transaction facilities. For example, a REST controller can use an injected service and repository to retrieve account data.

2
New cards

What is dependency injection?

Supplying dependencies to an object instead of creating them inside the object. For example, Spring injects an existing UserService bean into a UserController constructor. The controller depends on an abstraction it receives rather than managing object creation itself.

3
New cards

What is inversion of control (IoC)?

Outsourcing object construction and management to the Spring container. With IoC, the framework manages the lifecycle and wiring of objects rather than application code manually orchestrating them. Dependency injection is one way Spring puts IoC into practice.

4
New cards

How is DI related to IoC?

Dependency injection is a way to implement the inversion of control principle. IoC describes who has control over constructing and wiring objects; DI is the mechanism of passing those objects into their consumers. Constructor injection is a common Spring example.

5
New cards

What is Spring Boot?

A framework built on Spring that simplifies setup with auto-configuration and embedded servers. For example, adding the Spring Web starter can configure the pieces required to serve REST endpoints using an embedded server. Spring Boot remains part of the broader Spring ecosystem.

6
New cards

Spring vs Spring Boot?

Spring is the foundation; Spring Boot reduces manual configuration and startup effort. With plain Spring, developers may configure more beans and infrastructure manually. Boot retains Spring features while providing sensible defaults that can still be overridden.

7
New cards

What is convention over configuration?

Using sensible defaults instead of manually configuring everything. Boot selects typical configurations based on project dependencies and declared settings. A developer can override these defaults when the application requires different behavior.

8
New cards

What is Spring Initializr?

A tool for generating a Spring Boot starter project with dependencies and build files. You select Java, Maven or Gradle, project metadata, and starters such as Spring Web or Spring Data JPA. It creates the initial project structure instead of having you assemble it manually.

9
New cards

Which build tools can Spring Initializr generate?

Maven and Gradle. Both handle project builds and external libraries: Maven uses pom.xml and Gradle typically uses build.gradle. The choice affects the build workflow, not Spring concepts such as DI.

10
New cards

What is Spring Tools Suite?

Tooling for Spring development, traditionally Eclipse-based and also supporting VS Code. These extensions can help create Spring projects, navigate beans, and work with framework configuration. They improve development ergonomics but do not run the application in production.

11
New cards

What is a JAR file?

A Java archive; Spring Boot executable JARs commonly include an embedded web server. A Spring Boot executable JAR can include application classes, dependencies, and an embedded servlet server. That allows starting the app with java -jar without a separate deployment step.

12
New cards

What is a WAR file?

A web application archive traditionally deployed to a separately configured server. WAR deployment is common when an organization already manages a servlet container. By contrast, an executable Boot JAR usually starts its own embedded server.

13
New cards

How do you start a Maven Spring Boot application?

Run mvn spring-boot:run or use the Maven wrapper. This runs the main Boot application from the Maven project, usually starting an embedded server. Use Ctrl+C to stop the process during local development.

14
New cards

What is Spring Boot's default web port?

8080. For example, the slides visit http://localhost:8080 after starting a controller. You can override the port using server.port in your application configuration.

15
New cards

What is pom.xml?

The Maven file for dependencies, plugins, and build configuration. You declare starters, JDBC drivers, and plugins here so Maven can resolve required libraries. Example: adding spring-boot-starter-data-jpa enables JPA-related dependencies.

16
New cards

What is the Maven Wrapper?

Project scripts such as mvnw that run Maven using the project's specified distribution. In a typical Spring Boot project, you select dependencies, configure environment-specific settings, and run the application with Maven or a packaged executable. Its defaults reduce setup work while still allowing customization.

17
New cards

What are application.properties and application.yml?

Files for application configuration, such as ports, database credentials, and logging. For example, set spring.datasource.url to the database JDBC URL, plus username and password. YAML groups nested options; properties uses dotted keys.

18
New cards

Where does static web content usually go?

src/main/resources/static. Think of a concrete example from a Spring Boot application and explain when you would use this feature, not just its definition. Describe the behavior that changes when the feature is present.

19
New cards

What are server-side templates for?

Rendering markup views on the server instead of just returning JSON. Think of a concrete example from a Spring Boot application and explain when you would use this feature, not just its definition. Describe the behavior that changes when the feature is present.

20
New cards

What does spring-boot-starter-web include?

Dependencies for REST and web development, including Spring MVC and a servlet server. The Web starter brings the components needed for HTTP handlers and typical REST applications. In the course example, @GetMapping on a @RestController exposes Hello World.

21
New cards

What does spring-boot-starter-data-jpa include?

Spring Data JPA integration, with Hibernate commonly acting as the JPA provider. In a typical Spring Boot project, you select dependencies, configure environment-specific settings, and run the application with Maven or a packaged executable. Its defaults reduce setup work while still allowing customization.

22
New cards

What does spring-boot-starter-test include?

Testing support such as JUnit, Mockito, and Spring Test. In a typical Spring Boot project, you select dependencies, configure environment-specific settings, and run the application with Maven or a packaged executable. Its defaults reduce setup work while still allowing customization.

23
New cards

What is the Spring Boot starter parent?

A Maven parent providing dependency versions and useful build defaults. In a typical Spring Boot project, you select dependencies, configure environment-specific settings, and run the application with Maven or a packaged executable. Its defaults reduce setup work while still allowing customization.

24
New cards

What is DevTools?

Development tools that help restart applications after code changes. In a typical Spring Boot project, you select dependencies, configure environment-specific settings, and run the application with Maven or a packaged executable. Its defaults reduce setup work while still allowing customization.

25
New cards

What is Spring Boot Actuator?

A project exposing operational endpoints, including health and metrics. For example, /actuator/health can help operators check whether an application is healthy. Expose only appropriate endpoints and secure sensitive ones.

26
New cards

What does /actuator/health report?

Application health status, often UP or DOWN. In a typical Spring Boot project, you select dependencies, configure environment-specific settings, and run the application with Maven or a packaged executable. Its defaults reduce setup work while still allowing customization.

27
New cards

Why restrict Actuator endpoint exposure?

Operational details can expose sensitive system information. In a typical Spring Boot project, you select dependencies, configure environment-specific settings, and run the application with Maven or a packaged executable. Its defaults reduce setup work while still allowing customization.

28
New cards

Where can logging levels be configured?

In application.properties or application.yml. In a typical Spring Boot project, you select dependencies, configure environment-specific settings, and run the application with Maven or a packaged executable. Its defaults reduce setup work while still allowing customization.

29
New cards

What does a Spring container do?

Creates, configures, injects, and manages bean lifecycles. Think of a concrete example from a Spring Boot application and explain when you would use this feature, not just its definition. Describe the behavior that changes when the feature is present.

30
New cards

What is a Spring bean?

An object managed by the Spring container. Spring manages the relevant object within its application context; annotations and scanning determine which classes are registered. This keeps wiring and lifecycle responsibilities out of normal business code.

31
New cards

What is constructor injection?

Passing dependencies through a constructor; preferred for required dependencies. For example, a controller can receive a UserService through its constructor instead of creating it with new. This reduces coupling and lets tests supply a mock service.

32
New cards

What is setter injection?

Supplying dependencies through setter methods after construction. For example, a controller can receive a UserService through its constructor instead of creating it with new. This reduces coupling and lets tests supply a mock service.

33
New cards

What is field injection?

Injecting dependencies directly into fields; generally less testable. For example, a controller can receive a UserService through its constructor instead of creating it with new. This reduces coupling and lets tests supply a mock service.

34
New cards

What is @Autowired?

An annotation used to request dependency injection from Spring. For example, a controller can receive a UserService through its constructor instead of creating it with new. This reduces coupling and lets tests supply a mock service.

35
New cards

What is @Component?

An annotation identifying a class as a Spring-managed component. Spring manages the relevant object within its application context; annotations and scanning determine which classes are registered. This keeps wiring and lifecycle responsibilities out of normal business code.

36
New cards

What does component scanning do?

Discovers eligible component classes in configured packages. Spring manages the relevant object within its application context; annotations and scanning determine which classes are registered. This keeps wiring and lifecycle responsibilities out of normal business code.

37
New cards

What does @SpringBootApplication encompass?

Boot configuration, auto-configuration, and component scanning. Think of a concrete example from a Spring Boot application and explain when you would use this feature, not just its definition. Describe the behavior that changes when the feature is present.

38
New cards

What does @Qualifier do?

Selects a specific bean when multiple beans match the same type. For example, a controller can receive a UserService through its constructor instead of creating it with new. This reduces coupling and lets tests supply a mock service.

39
New cards

What does @Primary do?

Marks a preferred bean among multiple matching candidates. For example, a controller can receive a UserService through its constructor instead of creating it with new. This reduces coupling and lets tests supply a mock service.

40
New cards

What is default bean scope?

Singleton, meaning one bean instance per container bean definition. Spring manages the relevant object within its application context; annotations and scanning determine which classes are registered. This keeps wiring and lifecycle responsibilities out of normal business code.

41
New cards

What is prototype scope?

A new bean instance is created each time the container is asked for one. Spring manages the relevant object within its application context; annotations and scanning determine which classes are registered. This keeps wiring and lifecycle responsibilities out of normal business code.

42
New cards

What does @Lazy do?

Delays bean initialization until first needed. Spring manages the relevant object within its application context; annotations and scanning determine which classes are registered. This keeps wiring and lifecycle responsibilities out of normal business code.

43
New cards

What does @PostConstruct do?

Marks an initialization method run after dependency injection. Spring manages the relevant object within its application context; annotations and scanning determine which classes are registered. This keeps wiring and lifecycle responsibilities out of normal business code.

44
New cards

What does @PreDestroy do?

Marks a cleanup callback before a managed bean is destroyed. Spring manages the relevant object within its application context; annotations and scanning determine which classes are registered. This keeps wiring and lifecycle responsibilities out of normal business code.

45
New cards

Why use @Configuration and @Bean?

To explicitly register beans, including types you cannot annotate yourself. Spring manages the relevant object within its application context; annotations and scanning determine which classes are registered. This keeps wiring and lifecycle responsibilities out of normal business code.

46
New cards

What is ORM?

Object-relational mapping between Java objects and relational database tables. Instead of manually reading JDBC ResultSet rows, a mapped Student object can represent a row of the student table. ORM maps properties and relationships to database structures.

47
New cards

What is Hibernate?

An ORM implementation that persists Java objects to relational databases. Hibernate translates entity operations into SQL and coordinates entity state within a Session or persistence context. JDBC still operates underneath, even when applications do not use JDBC directly.

48
New cards

What does JPA stand for?

Jakarta Persistence API, a specification for Java object persistence. The specification describes portable persistence concepts and interfaces, including EntityManager. Providers such as Hibernate and EclipseLink implement those contracts.

49
New cards

How is Hibernate related to JPA?

Hibernate implements the JPA specification. You code against standard JPA interfaces while Hibernate supplies the underlying behavior. That can reduce dependence on one persistence provider, though vendor-specific features still exist.

50
New cards

Why use Hibernate instead of plain JDBC?

It reduces manual SQL, result mapping, and persistence boilerplate. In a Student application, an entity maps Java fields to database columns, while the persistence provider translates changes into SQL through JDBC. The ORM reduces repetitive data-access code but still requires correct mappings and transactions.

51
New cards

Which JDBC driver is used in the slides for PostgreSQL?

The PostgreSQL JDBC driver, org.postgresql:postgresql. In a Student application, an entity maps Java fields to database columns, while the persistence provider translates changes into SQL through JDBC. The ORM reduces repetitive data-access code but still requires correct mappings and transactions.

52
New cards

Which properties commonly connect Spring to a database?

spring.datasource.url, spring.datasource.username, and spring.datasource.password. In a Student application, an entity maps Java fields to database columns, while the persistence provider translates changes into SQL through JDBC. The ORM reduces repetitive data-access code but still requires correct mappings and transactions.

53
New cards

What is EntityManager?

The JPA API for interacting with a persistence context and managing entities. Typical operations include persist to manage a new entity and find to locate one by primary key. It offers more direct control over persistence behavior than a standard JpaRepository.

54
New cards

What is JpaRepository?

A Spring Data abstraction offering CRUD, sorting, pagination, and queries. For example, interface StudentRepository extends JpaRepository

55
New cards

EntityManager vs JpaRepository?

EntityManager provides lower-level control; JpaRepository simplifies common CRUD work. In a Student application, an entity maps Java fields to database columns, while the persistence provider translates changes into SQL through JDBC. The ORM reduces repetitive data-access code but still requires correct mappings and transactions.

56
New cards

What is a persistence context?

The managed set of entity instances tracked by a JPA provider. The context tracks entity identity and changes. When a managed entity is changed in a transaction, Hibernate can detect those changes and write the updates during flush.

57
New cards

What is Hibernate Session?

Hibernate's API for interacting with persistent entities and the database. In a Student application, an entity maps Java fields to database columns, while the persistence provider translates changes into SQL through JDBC. The ORM reduces repetitive data-access code but still requires correct mappings and transactions.

58
New cards

What is JPQL?

A query language that uses entity names and properties rather than database table names. For example, SELECT s FROM Student s addresses the Student Java entity, not the students table. JPQL helps keep queries based on mapped domain classes.

59
New cards

What is HQL?

Hibernate's query language, similar to JPQL with Hibernate-specific extensions. The important distinction is whether you query mapped entity properties or physical database tables. Choose straightforward repository methods for simple lookups and explicit queries for more complex cases.

60
New cards

What is native SQL?

Database SQL that directly references tables and columns. For example, SELECT * FROM students uses actual table and column names. Native SQL can use database-specific features but reduces portability compared with JPQL.

61
New cards

What does SELECT s FROM Student s reference?

The Student entity class, not necessarily a table called Student. The important distinction is whether you query mapped entity properties or physical database tables. Choose straightforward repository methods for simple lookups and explicit queries for more complex cases.

62
New cards

What does @Entity mark?

A class representing a persistent JPA entity. In a Student application, an entity maps Java fields to database columns, while the persistence provider translates changes into SQL through JDBC. The ORM reduces repetitive data-access code but still requires correct mappings and transactions.

63
New cards

What does @Id mark?

An entity's primary-key attribute. In a Student application, an entity maps Java fields to database columns, while the persistence provider translates changes into SQL through JDBC. The ORM reduces repetitive data-access code but still requires correct mappings and transactions.

64
New cards

What does @GeneratedValue configure?

Automatic primary-key generation. In a Student application, an entity maps Java fields to database columns, while the persistence provider translates changes into SQL through JDBC. The ORM reduces repetitive data-access code but still requires correct mappings and transactions.

65
New cards

What does @Service mark?

A Spring component holding business logic. Spring manages the relevant object within its application context; annotations and scanning determine which classes are registered. This keeps wiring and lifecycle responsibilities out of normal business code.

66
New cards

What does @Repository mark?

A Spring component handling data access. Spring manages the relevant object within its application context; annotations and scanning determine which classes are registered. This keeps wiring and lifecycle responsibilities out of normal business code.

67
New cards

What does @RestController mark?

A controller whose request handlers typically return response bodies such as JSON. For example, an Angular client can send JSON to a Spring REST endpoint; the controller binds the request to a Java object, calls a service, then returns a response. Keep HTTP handling separate from business and persistence logic.

68
New cards

What is Jackson?

A library for converting Java objects to and from JSON. When a REST method returns a Java object, Jackson typically serializes it to JSON; when @RequestBody receives JSON, it deserializes it into a Java object.

69
New cards

What is serialization?

Converting a Java object into JSON or another transport format. For example, an Angular client can send JSON to a Spring REST endpoint; the controller binds the request to a Java object, calls a service, then returns a response. Keep HTTP handling separate from business and persistence logic.

70
New cards

What is deserialization?

Converting JSON into a Java object. For example, an Angular client can send JSON to a Spring REST endpoint; the controller binds the request to a Java object, calls a service, then returns a response. Keep HTTP handling separate from business and persistence logic.

71
New cards

What does @NotNull validate?

A value must not be null. For example, a registration endpoint can reject a blank email before persisting the record. Application-level validation provides useful client errors; database constraints provide another layer of protection.

72
New cards

What does @NotEmpty validate?

A string, collection, or array must not be null or empty. For example, a registration endpoint can reject a blank email before persisting the record. Application-level validation provides useful client errors; database constraints provide another layer of protection.

73
New cards

What does @NotBlank validate?

A string cannot be null, empty, or whitespace-only. For example, a registration endpoint can reject a blank email before persisting the record. Application-level validation provides useful client errors; database constraints provide another layer of protection.

74
New cards

What does @Valid trigger?

Bean Validation for an annotated argument or object. For example, @Valid @RequestBody StudentDto validates the DTO against constraints like @NotBlank before normal controller processing continues.

75
New cards

What does @Column(nullable=false) request?

A non-null database column constraint in generated schema mapping. For example, a registration endpoint can reject a blank email before persisting the record. Application-level validation provides useful client errors; database constraints provide another layer of protection.

76
New cards

What is a custom runtime exception for?

Representing an application-specific error such as a missing record. In a typical Spring Boot project, you select dependencies, configure environment-specific settings, and run the application with Maven or a packaged executable. Its defaults reduce setup work while still allowing customization.

77
New cards

What is @RestControllerAdvice?

Global REST controller advice, often used for exception handling. A request for a missing record should return a clear error body and an appropriate HTTP status, such as 404. Centralized exception handling avoids duplicating this logic in every controller.

78
New cards

What does @ExceptionHandler do?

Maps a particular exception type to a handler method. A request for a missing record should return a clear error body and an appropriate HTTP status, such as 404. Centralized exception handling avoids duplicating this logic in every controller.

79
New cards

Why return ResponseEntity?

To specify an HTTP status, headers, and response body. A controller can return ResponseEntity.status(404).body(error) when a resource is absent. This clearly communicates both the HTTP result and explanatory payload.

80
New cards

What does @Transactional do?

Declares a transaction boundary managed by Spring. In a transfer service, both account balance updates should be committed as one unit or rolled back together. Spring normally manages this around the transactional method.

81
New cards

What is REQUIRED propagation?

Joins an existing transaction or creates one if absent. For a banking transfer, both the debit and credit should succeed together or be rolled back together. Transaction configuration determines when work commits and how it interacts with concurrent requests.

82
New cards

What is REQUIRES_NEW propagation?

Suspends the current transaction and starts a separate one. For a banking transfer, both the debit and credit should succeed together or be rolled back together. Transaction configuration determines when work commits and how it interacts with concurrent requests.

83
New cards

What does transaction isolation control?

How concurrent transactions see each other's changes. For a banking transfer, both the debit and credit should succeed together or be rolled back together. Transaction configuration determines when work commits and how it interacts with concurrent requests.

84
New cards

What does @OneToOne map?

A relationship with one related entity on each side. For instance, one customer may own multiple accounts, so you must model the owning side and any foreign-key column correctly. Fetch strategy matters because loading associations unnecessarily can hurt performance.

85
New cards

What does @OneToMany map?

One entity related to multiple others. For instance, one customer may own multiple accounts, so you must model the owning side and any foreign-key column correctly. Fetch strategy matters because loading associations unnecessarily can hurt performance.

86
New cards

What does @ManyToOne map?

Multiple entities related to one parent entity. For instance, one customer may own multiple accounts, so you must model the owning side and any foreign-key column correctly. Fetch strategy matters because loading associations unnecessarily can hurt performance.

87
New cards

What does @ManyToMany map?

Multiple entities on each side related to multiple on the other. For instance, one customer may own multiple accounts, so you must model the owning side and any foreign-key column correctly. Fetch strategy matters because loading associations unnecessarily can hurt performance.

88
New cards

What does mappedBy identify?

The owning-side property of a bidirectional JPA relationship. For a Customer with accounts, the Customer.accounts collection may use mappedBy="customer" if Account.customer owns the join column. The inverse side does not define that foreign key.

89
New cards

Why create a join entity for many-to-many?

To store additional attributes about the relationship itself. For instance, one customer may own multiple accounts, so you must model the owning side and any foreign-key column correctly. Fetch strategy matters because loading associations unnecessarily can hurt performance.

90
New cards

How do you declare a repository?

An interface extending JpaRepository

91
New cards

What can JpaRepository.findById return?

Optional, accounting for a missing record. The caller should handle both the present and absent case; using Optional avoids assuming every requested record exists. A missing result may become a 404 in a REST controller.

92
New cards

What are derived query methods?

Repository query methods parsed from names such as findByEmail. The important distinction is whether you query mapped entity properties or physical database tables. Choose straightforward repository methods for simple lookups and explicit queries for more complex cases.

93
New cards

What does countByStatus mean?

Count entity records where the status property matches. The important distinction is whether you query mapped entity properties or physical database tables. Choose straightforward repository methods for simple lookups and explicit queries for more complex cases.

94
New cards

What goes after By in a derived method name?

Entity property names and conditions that define the filter. Think of a concrete example from a Spring Boot application and explain when you would use this feature, not just its definition. Describe the behavior that changes when the feature is present.

95
New cards

When should you avoid derived query methods?

When query names become too long or relationship traversal becomes complex. The important distinction is whether you query mapped entity properties or physical database tables. Choose straightforward repository methods for simple lookups and explicit queries for more complex cases.

96
New cards

What does @Query do?

Defines a custom JPQL or native SQL repository query. The important distinction is whether you query mapped entity properties or physical database tables. Choose straightforward repository methods for simple lookups and explicit queries for more complex cases.

97
New cards

What does Pageable represent?

Pagination input, including page number, size, and often sorting. For example, PageRequest.of(0, 20) requests the first page of 20 records. This avoids returning an unbounded result set to the API caller.

98
New cards

What is a DTO?

A data transfer object that shapes request or response data. For example, AccountResponseDto can expose account number and balance without exposing internal entity fields. DTOs help keep persistence mappings separate from API contracts.

99
New cards

Why use DTOs?

To control API data and separate API contracts from persistence entities. For example, an Angular client can send JSON to a Spring REST endpoint; the controller binds the request to a Java object, calls a service, then returns a response. Keep HTTP handling separate from business and persistence logic.

100
New cards

How can derived queries navigate relationships?

With property paths, including underscores to disambiguate traversal. For instance, one customer may own multiple accounts, so you must model the owning side and any foreign-key column correctly. Fetch strategy matters because loading associations unnecessarily can hurt performance.