IoC, Boot auto-config, REST, data access, transactions, security
Practise these as flashcards. One or two lines each; the ones you miss come back first.
Start freeInversion of Control means the framework, not the application code, controls object creation and wiring. Spring implements this using Dependency Injection, where beans and their dependencies are managed by the IoC container.
The main bean scopes are singleton (one instance per container), prototype (a new instance every time it's requested), request (one per HTTP request), and session (one per HTTP session). Singleton is the default.
I use @RestController on the class and map endpoints with @RequestMapping, @GetMapping, @PostMapping, etc. Methods return objects, which are automatically serialized to JSON.
A starter is a dependency that bundles related libraries for a specific feature, like spring-boot-starter-web for web apps. It simplifies dependency management.
Spring Boot auto-configuration inspects the classpath and application properties to automatically configure beans for common use cases. It uses @Conditional annotations to activate configurations only when needed, reducing manual setup.
I use application.properties or application.yml files, and can override settings with environment variables or command-line arguments. For different environments, I use profile-specific files like application-dev.properties.
I annotate the DTO fields with validation annotations like @NotNull, and add @Valid to the controller method parameter. Spring automatically validates and throws an exception if validation fails.
The N+1 problem happens when fetching a list of entities causes additional queries for each related entity due to lazy loading. I avoid it by using fetch joins in JPQL or @EntityGraph to load associations eagerly when needed.
Constructor injection passes dependencies via the constructor, making them explicit and supporting immutability. Field injection uses @Autowired on fields, which is less visible and harder to test, so I prefer constructor injection.
Spring Security sets up a chain of filters that process each request, handling authentication, authorization, and other security concerns. Each filter can allow, modify, or block the request based on security rules.
I use @WebMvcTest to load only the web layer and MockMvc to simulate HTTP requests. This allows fast, focused tests of controller logic without starting the full application.
@Transactional marks a method or class as transactional. Propagation defines how transactions behave when a transactional method calls another transactional method, for example, joining an existing transaction or starting a new one.