Spring

Раздел про Spring и Spring Boot: DI/IoC, auto-configuration, MVC, WebFlux, @Transactional, Spring Data JPA, Events, AOP, Security, Testing, Actuator/Observability, Scheduled/Async/Virtual Threads. Объяснения с примерами кода.

Why it matters for UCP. Spring/Spring Boot is the foundation of every UCP service. Without understanding DI, lifecycle, transactions, AOP, and Spring Data, you cannot write Handlers deliberately or integrate infrastructure. Part of the training program.

The section is split into 13 articles. You can read them in order (foundation → web → transactions/data → advanced → operations) or pick specific topics.

Foundation

  1. DI/IoC, bean scopes — the ApplicationContext, how Spring creates beans, scopes, @Configuration vs @Component, conditional beans.
  2. Bean lifecycle with examples — eight phases from constructor to destruction, with working demo code, console output, and a breakdown of the pitfalls.
  3. Auto-configuration, properties, profiles — how @EnableAutoConfiguration works under the hood, @ConfigurationProperties, profiles, a custom starter.

Web

  1. Spring MVC: REST, validation, exception handlers@RestController, validation via Bean Validation, unified error handling, HandlerInterceptor, content negotiation.
  2. Spring WebFlux: when to use it, Mono/Flux, R2DBC — the reactive stack, how it differs from MVC, when it's justified, common pitfalls.

Transactions and data

  1. @Transactional in depth: propagation, isolation, pitfalls — how the proxy works, self-invocation, checked exceptions, propagation REQUIRED/REQUIRES_NEW/NESTED, rollback rules.
  2. Spring Data JPA: repositories, projections, OSIV — query methods, JPQL, paging, projections, fetch strategies, the OSIV problem, when to use native SQL.

Messaging and events

  1. Spring Events: @EventListener, @TransactionalEventListener, AsyncEvents — synchronous and asynchronous events, events bound to a transaction, as a domain event publisher.
  2. Spring AOP: when you need it, @Aspect, limitations — concepts, pointcut, advice, how Spring instruments beans, limitations (final, self-invocation).

Security

  1. Spring Security: filters, AuthN, AuthZ, OAuth2 — the SecurityFilterChain, authentication and authorization, method security, OAuth2 resource server and client.

Testing

  1. Spring Testing: @SpringBootTest, slices, TestContainers@WebMvcTest, @DataJpaTest, MockMvc, WebTestClient, TestContainers for integration tests.

Operations

  1. Actuator, metrics, tracing — health, info, custom endpoints, Micrometer, distributed tracing.
  2. Scheduled, Async, virtual threads@Scheduled, @Async, thread pools, Java 21+ virtual threads.