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

0.0(0)
Studied by 1 person
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.

256 Terms

1
New cards

What is Spring?

A Java framework used to build web applications, APIs, and enterprise applications.

2
New cards

What is dependency injection?

Supplying dependencies to an object instead of creating them inside the object.

3
New cards

What is inversion of control (IoC)?

Outsourcing object construction and management to the Spring container.

4
New cards

How is DI related to IoC?

Dependency injection is a way to implement the inversion of control principle.

5
New cards

What is Spring Boot?

A framework built on Spring that simplifies setup with auto-configuration and embedded servers.

6
New cards

Spring vs Spring Boot?

Spring is the foundation; Spring Boot reduces manual configuration and startup effort.

7
New cards

What is convention over configuration?

Using sensible defaults instead of manually configuring everything.

8
New cards

What is Spring Initializr?

A tool for generating a Spring Boot starter project with dependencies and build files.

9
New cards

Which build tools can Spring Initializr generate?

Maven and Gradle.

10
New cards

What is Spring Tools Suite?

Tooling for Spring development, traditionally Eclipse-based and also supporting VS Code.

11
New cards

What is a JAR file?

A Java archive; Spring Boot executable JARs commonly include an embedded web server.

12
New cards

What is a WAR file?

A web application archive traditionally deployed to a separately configured server.

13
New cards

How do you start a Maven Spring Boot application?

Run mvn spring-boot:run or use the Maven wrapper.

14
New cards

What is Spring Boot's default web port?

8080

15
New cards

What is pom.xml?

The Maven file for dependencies, plugins, and build configuration.

16
New cards

What is the Maven Wrapper?

Project scripts such as mvnw that run Maven using the project's specified distribution.

17
New cards

What are application.properties and application.yml?

Files for application configuration, such as ports, database credentials, and logging.

18
New cards

Where does static web content usually go?

src/main/resources/static.

19
New cards

What are server-side templates for?

Rendering markup views on the server instead of just returning JSON.

20
New cards

What does spring-boot-starter-web include?

Dependencies for REST and web development, including Spring MVC and a servlet server.

21
New cards

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

Spring Data JPA integration, with Hibernate commonly acting as the JPA provider.

22
New cards

What does spring-boot-starter-test include?

Testing support such as JUnit, Mockito, and Spring Test.

23
New cards

What is the Spring Boot starter parent?

A Maven parent providing dependency versions and useful build defaults.

24
New cards

What is DevTools?

Development tools that help restart applications after code changes.

25
New cards

What is Spring Boot Actuator?

A project exposing operational endpoints, including health and metrics.

26
New cards

What does /actuator/health report?

Application health status, often UP or DOWN.

27
New cards

Why restrict Actuator endpoint exposure?

Operational details can expose sensitive system information.

28
New cards

Where can logging levels be configured?

In application.properties or application.yml.

29
New cards

What does a Spring container do?

Creates, configures, injects, and manages bean lifecycles.

30
New cards

What is a Spring bean?

An object managed by the Spring container.

31
New cards

What is constructor injection?

Passing dependencies through a constructor; preferred for required dependencies.

32
New cards

What is setter injection?

Supplying dependencies through setter methods after construction.

33
New cards

What is field injection?

Injecting dependencies directly into fields; generally less testable.

34
New cards

What is @Autowired?

An annotation used to request dependency injection from Spring.

35
New cards

What is @Component?

An annotation identifying a class as a Spring-managed component.

36
New cards

What does component scanning do?

Discovers eligible component classes in configured packages.

37
New cards

What does @SpringBootApplication encompass?

Boot configuration, auto-configuration, and component scanning.

38
New cards

What does @Qualifier do?

Selects a specific bean when multiple beans match the same type.

39
New cards

What does @Primary do?

Marks a preferred bean among multiple matching candidates.

40
New cards

What is default bean scope?

Singleton, meaning one bean instance per container bean definition.

41
New cards

What is prototype scope?

A new bean instance is created each time the container is asked for one.

42
New cards

What does @Lazy do?

Delays bean initialization until first needed.

43
New cards

What does @PostConstruct do?

Marks an initialization method run after dependency injection.

44
New cards

What does @PreDestroy do?

Marks a cleanup callback before a managed bean is destroyed.

45
New cards

Why use @Configuration and @Bean?

To explicitly register beans, including types you cannot annotate yourself.

46
New cards

What is ORM?

Object-relational mapping between Java objects and relational database tables.

47
New cards

What is Hibernate?

An ORM implementation that persists Java objects to relational databases.

48
New cards

What does JPA stand for?

Jakarta Persistence API, a specification for Java object persistence.

49
New cards

How is Hibernate related to JPA?

Hibernate implements the JPA specification.

50
New cards

Why use Hibernate instead of plain JDBC?

It reduces manual SQL, result mapping, and persistence boilerplate.

51
New cards

Which JDBC driver is used in the slides for PostgreSQL?

The PostgreSQL JDBC driver, org.postgresql:postgresql.

52
New cards

Which properties commonly connect Spring to a database?

spring.datasource.url, spring.datasource.username, and spring.datasource.password.

53
New cards

What is EntityManager?

The JPA API for interacting with a persistence context and managing entities.

54
New cards

What is JpaRepository?

A Spring Data abstraction offering CRUD, sorting, pagination, and queries.

55
New cards

EntityManager vs JpaRepository?

EntityManager provides lower-level control; JpaRepository simplifies common CRUD work.

56
New cards

What is a persistence context?

The managed set of entity instances tracked by a JPA provider.

57
New cards

What is Hibernate Session?

Hibernate's API for interacting with persistent entities and the database.

58
New cards

What is JPQL?

A query language that uses entity names and properties rather than database table names.

59
New cards

What is HQL?

Hibernate's query language, similar to JPQL with Hibernate-specific extensions.

60
New cards

What is native SQL?

Database SQL that directly references tables and columns.

61
New cards

What does SELECT s FROM Student s reference?

The Student entity class, not necessarily a table called Student.

62
New cards

What does @Entity mark?

A class representing a persistent JPA entity.

63
New cards

What does @Id mark?

An entity's primary-key attribute.

64
New cards

What does @GeneratedValue configure?

Automatic primary-key generation.

65
New cards

What does @Service mark?

A Spring component holding business logic.

66
New cards

What does @Repository mark?

A Spring component handling data access.

67
New cards

What does @RestController mark?

A controller whose request handlers typically return response bodies such as JSON.

68
New cards

What is Jackson?

A library for converting Java objects to and from JSON.

69
New cards

What is serialization?

Converting a Java object into JSON or another transport format.

70
New cards

What is deserialization?

Converting JSON into a Java object.

71
New cards

What does @NotNull validate?

A value must not be null.

72
New cards

What does @NotEmpty validate?

A string, collection, or array must not be null or empty.

73
New cards

What does @NotBlank validate?

A string cannot be null, empty, or whitespace-only.

74
New cards

What does @Valid trigger?

Bean Validation for an annotated argument or object.

75
New cards

What does @Column(nullable=false) request?

A non-null database column constraint in generated schema mapping.

76
New cards

What is a custom runtime exception for?

Representing an application-specific error such as a missing record.

77
New cards

What is @RestControllerAdvice?

Global REST controller advice, often used for exception handling.

78
New cards

What does @ExceptionHandler do?

Maps a particular exception type to a handler method.

79
New cards

Why return ResponseEntity?

To specify an HTTP status, headers, and response body.

80
New cards

What does @Transactional do?

Declares a transaction boundary managed by Spring.

81
New cards

What is REQUIRED propagation?

Joins an existing transaction or creates one if absent.

82
New cards

What is REQUIRES_NEW propagation?

Suspends the current transaction and starts a separate one.

83
New cards

What does transaction isolation control?

How concurrent transactions see each other's changes.

84
New cards

What does @OneToOne map?

A relationship with one related entity on each side.

85
New cards

What does @OneToMany map?

One entity related to multiple others.

86
New cards

What does @ManyToOne map?

Multiple entities related to one parent entity.

87
New cards

What does @ManyToMany map?

Multiple entities on each side related to multiple on the other.

88
New cards

What does mappedBy identify?

The owning-side property of a bidirectional JPA relationship.

89
New cards

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

To store additional attributes about the relationship itself.

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.

92
New cards

What are derived query methods?

Repository query methods parsed from names such as findByEmail.

93
New cards

What does countByStatus mean?

Count entity records where the status property matches.

94
New cards

What goes after By in a derived method name?

Entity property names and conditions that define the filter.

95
New cards

When should you avoid derived query methods?

When query names become too long or relationship traversal becomes complex.

96
New cards

What does @Query do?

Defines a custom JPQL or native SQL repository query.

97
New cards

What does Pageable represent?

Pagination input, including page number, size, and often sorting.

98
New cards

What is a DTO?

A data transfer object that shapes request or response data.

99
New cards

Why use DTOs?

To control API data and separate API contracts from persistence entities.

100
New cards

How can derived queries navigate relationships?

With property paths, including underscores to disambiguate traversal.