Spring Framework is a comprehensive, lightweight, and widely-used open-source application framework for Java platform. It provides infrastructure support for developing Java applications, making it easier to create enterprise-level applications.
Dependency Injection (DI) is a core concept in Spring where objects are given their dependencies instead of creating them internally. This promotes loose coupling and makes code more testable and maintainable. Spring container injects dependencies automatically based on configuration.
Spring Beans are objects that form the backbone of a Spring application. They are created, managed, and configured by the Spring IoC container. Beans are defined in the application context and can be retrieved when needed.
Inversion of Control (IoC) is a principle where control over object creation and lifecycle is transferred to the Spring container instead of the developer creating objects directly. This is a fundamental aspect of Spring that enables loose coupling.
Spring MVC is built on the Model-View-Controller pattern. The DispatcherServlet handles requests and routes them to appropriate controllers. Controllers process requests and return a model and view name. Views render the final response.
@Autowired is a Spring annotation used for automatic dependency injection. It lets Spring automatically resolve and inject collaborating beans into your bean. It can be used on constructors, methods, or fields.
Spring beans have different scopes: singleton (default, one instance per container), prototype (new instance each time requested), request (per HTTP request), session (per HTTP session), and application (per ServletContext).
Spring Boot is a Spring project that simplifies the creation of production-grade Spring applications. It provides auto-configuration, embedded servers, and 'starters' to minimize boilerplate code and configuration.
Spring annotations are special markers that provide metadata about classes. Common ones include @Component, @Service, @Repository, @Controller, @RestController, @Autowired, and @RequestMapping. They simplify configuration and reduce XML usage.
Aspect-Oriented Programming (AOP) in Spring allows separation of cross-cutting concerns like logging, security, and transactions from business logic. It enables adding behavior to existing code without modifying the code itself.
@ComponentScan tells Spring where to look for Spring components, configurations, and services. It scans specified packages for classes annotated with @Component, @Service, @Repository, and @Controller.
Spring Security is a powerful authentication and authorization framework. It provides comprehensive security services for Java EE-based enterprise software applications, protecting applications from various security threats.
@RequestMapping is used to map web requests to Spring Controller methods. It can be used to define URL patterns, HTTP methods, headers, and other request parameters that a method should handle.
Spring Data JPA simplifies data access layer implementation by reducing boilerplate code. It provides repository support for JPA and includes features like derived query methods and custom queries.
Spring Profiles allow configuring different sets of beans for different environments (dev, test, prod). They help manage application configuration for different deployment scenarios.
@Transactional annotation is used to manage database transactions. It ensures that a group of operations either complete successfully or roll back completely if an error occurs.
application.properties is a configuration file in Spring Boot that contains key-value pairs for configuring application behavior, database connections, server settings, and other properties.
Spring provides @ExceptionHandler for handling exceptions at controller level and @ControllerAdvice for global exception handling. It allows centralized exception handling across the application.
Spring Actuator provides production-ready features to help monitor and manage Spring Boot applications through REST endpoints, including health checks, metrics, and environment properties.
@Configuration marks a class as a source of bean definitions. These classes can contain @Bean annotated methods that return Spring beans, replacing traditional XML configuration.
@RestController is a convenience annotation that combines @Controller and @ResponseBody. It indicates that the class is a controller where every method returns a domain object instead of a view.
Spring bean lifecycle includes instantiation, populating properties, initialization (init-method), usage, and destruction (destroy-method). Beans can implement lifecycle interfaces or use annotations.
@Value annotation is used to inject values from properties files into variables. It can inject simple values, SpEL expressions, and environment variable values.
@Qualifier is used with @Autowired to specify which bean should be injected when multiple beans of the same type exist, avoiding autowiring ambiguity.
JdbcTemplate is a Spring class that simplifies JDBC operations by handling resource management and exception handling. It provides methods for querying and updating databases.
@PathVariable binds URI template variables to method parameters in controllers. It's used to handle dynamic values in URLs, like /users/{id} where {id} is variable.
@ResponseBody indicates that method return value should be bound to web response body. It's used to return data directly in response body instead of returning view name.
Spring provides validation through @Valid annotation and Validator interface. It supports both JSR-303/JSR-349 Bean Validation and custom validation logic.
@Service marks a class as service layer component in Spring. It's a specialization of @Component indicating that class holds business logic.
Spring container creates and manages Spring beans and their lifecycle. It uses dependency injection to manage components and provides an environment for beans to operate.
Spring WebFlux is a non-blocking reactive web framework introduced in Spring 5. It supports reactive programming, enabling building highly concurrent applications that can handle high loads with fewer resources using Project Reactor.
Spring Cloud provides tools for developers to quickly build common distributed system patterns like configuration management, service discovery, circuit breakers, routing, and microservices development.
Spring's caching abstraction allows transparent caching integration using @Cacheable, @CachePut, and @CacheEvict annotations. It supports various cache providers and implements caching aspects without modifying business logic.
Spring Retry provides declarative retry support for handling temporary failures. Using @Retryable, you can configure retry policies, backoff periods, and recovery methods for failed operations.
Spring Events enable communication between components using the Observer pattern. ApplicationEventPublisher publishes events, and @EventListener annotated methods handle them, enabling loose coupling.
Spring Method Security allows securing methods using annotations like @PreAuthorize, @PostAuthorize, and @Secured. It enables role-based access control and custom security expressions at method level.
Spring provides @Async for asynchronous execution, allowing methods to run in separate threads. It supports CompletableFuture, Future, and void return types with configurable thread pools.
Spring Integration implements Enterprise Integration Patterns for messaging, supporting various protocols and transformers. It enables building messaging-based integration solutions with declarative adapters.
Spring Batch provides robust batch processing capabilities with features like transaction management, chunk processing, and restart capability. It's designed for high-volume batch operations.
Spring AOP uses either JDK dynamic proxies (for interfaces) or CGLIB proxies (for classes) to implement aspect-oriented programming. Proxies intercept method calls to apply cross-cutting concerns.
@Conditional allows conditional bean registration based on specific conditions. It can use custom conditions, environment properties, bean presence, or system properties to determine bean creation.
Spring Data projections allow retrieving partial views of entities. Interface-based and class-based projections reduce payload size and improve performance by fetching only required fields.
Spring Expression Language (SpEL) is a powerful expression language supporting querying and manipulating object graphs at runtime. It's used in annotations, XML configuration, and programmatically.
Spring provides @CrossOrigin and CorsRegistry for handling Cross-Origin Resource Sharing. It allows configuring allowed origins, methods, headers, and credentials for cross-domain requests.
Spring TestContext Framework provides testing support with annotations like @ContextConfiguration and @SpringBootTest. It manages test contexts, caching, and dependency injection in tests.
Spring Cloud Circuit Breaker provides abstractions for implementing circuit breakers using various providers. It helps build resilient applications by handling remote service failures gracefully.
Spring's Converter interface allows type conversion between objects. Custom converters can be registered with ConversionService for automatic conversion during data binding and validation.
Spring Boot Actuator provides detailed operational information about application's internals, metrics, health checks, and environment properties through REST endpoints or JMX.
Spring's Cache Abstraction provides a consistent caching approach across various cache implementations. It supports declarative caching with flexible key generation and cache resolution.
Spring supports internationalization through MessageSource interface and ResourceBundle. It allows managing messages in different languages and locales using properties files.
Spring Scheduler enables declarative task scheduling using @Scheduled annotation. It supports cron expressions, fixed delays, and fixed rates for scheduling periodic tasks.
WebClient is Spring's reactive web client for HTTP requests. It provides a functional, fluent API for making synchronous and asynchronous HTTP calls with reactive support.
Spring Data repositories provide sophisticated CRUD operations through interfaces. They support derived queries, custom queries, and various database-specific features with minimal configuration.
Spring Session provides API and implementations for managing user session information. It supports various backend stores and enables session sharing across multiple applications.
Spring supports servlet filters through DelegatingFilterProxy and FilterRegistrationBean. Filters can be ordered and chained to process requests before reaching controllers.
Validation groups in Spring allow applying different validation rules to the same object based on context. They help organize and control validation constraints for different use cases.
ApplicationContext is Spring's advanced container providing enterprise features. It extends BeanFactory with AOP, event handling, resource loading, and internationalization support.
Spring Data Auditing automatically manages entity auditing (creation time, last modified time, etc.) using AuditorAware interface and annotations like @EntityListeners.
Profiles in Spring allow conditional bean registration and property loading based on environment. They help manage different configurations for development, testing, and production.
Spring uses Commons Logging by default but supports various logging frameworks. It provides logging abstractions and configuration options for different logging implementations.
Bean Post Processors allow customizing bean instances before and after initialization. They implement BeanPostProcessor interface and can modify bean properties or validate configurations globally.
@Lazy annotation defers bean creation until first usage, improving startup time. It can be used on components or injection points to control initialization behavior and resource usage.
Spring resolves circular dependencies using setter injection or method injection. Constructor injection causes circular dependency errors. It uses proxy objects during initialization phase.
@EnableTransactionManagement enables declarative transaction management. It processes @Transactional annotations, configures transaction aspects, and manages transaction boundaries and propagation.
AbstractRoutingDataSource enables dynamic datasource routing based on context. It supports multiple databases and allows switching between them at runtime using context keys.
Custom scopes can be implemented by extending AbstractBeanFactoryAwareScope. They require scope, conversation management, and bean lifecycle handling implementation.
PropertyEditors convert string values to complex types during data binding. Custom editors can be registered globally or per field for specialized type conversion.
BeanFactoryPostProcessor modifies bean definitions before instantiation. It can modify properties, add new beans, or transform configurations at container initialization.
@LoadBalanced creates a load-balanced RestTemplate using client-side load balancing. It integrates with service discovery and supports various load balancing strategies.
ProxyMode in @Scope controls how scoped beans are proxied. It handles shorter-lived beans injected into longer-lived contexts using runtime proxies.
HandlerInterceptors intercept requests before and after handler execution. They enable cross-cutting concerns like logging, security, or request modification globally.
Spring manages bean destruction through DisposableBean interface or @PreDestroy. It ensures proper resource cleanup and shutdown operations during container shutdown.
@EnableAspectJAutoProxy enables AspectJ-style AOP proxying. It controls proxy creation, optimization, and exposure of proxy objects to target objects.
ObjectProvider is an injection point API providing additional flexibility. It supports optional dependencies, multiple instances, and lazy resolution of beans.
Custom annotations can be created with meta-annotations and processed using BeanFactoryPostProcessor or custom annotation processors for specialized behavior.
@EnableCaching configures caching infrastructure with customizable key generation, cache resolution, and error handling. It supports various caching providers and strategies.
ApplicationListener handles application events asynchronously or synchronously. It enables loose coupling between components through event-driven architecture.
Method replacement uses CGLIB to replace bean methods at runtime. It's configured through lookup-method or replaced-method in XML or using @Lookup annotation.
@EnableWebSecurity configures WebSecurityConfiguration and authentication/authorization infrastructure. It sets up security filter chain and security context.
BeanDefinition holds bean metadata like class, scope, dependencies. It can be modified before bean instantiation for dynamic configuration adjustments.
Custom scopes require implementing Scope interface. They manage bean instances lifecycle and conversation state within defined scope boundaries.
@EnableScheduling sets up task scheduler infrastructure. It processes @Scheduled annotations and manages thread pools for scheduled task execution.
MessageConverter handles HTTP message conversion. Custom converters can be implemented for specialized content type handling in REST communications.
@Async creates proxy wrapping async methods. It delegates execution to TaskExecutor and handles Future/CompletableFuture return types.
@ConfigurationProperties binds external properties to beans. It supports relaxed binding, validation, and complex property structures.
ResourceLoader loads resources from various locations. It abstracts resource access and supports classpath, file system, and URL-based resources.
Custom serialization can be implemented through Jackson modules or custom serializers. Spring integrates with various serialization frameworks.
@EnableRetry configures retry infrastructure. It processes @Retryable annotations and manages retry policies, backoff strategies, and recovery methods.
RequestBodyAdvice customizes request body reading. It enables preprocessing or modification of request bodies before controller handling.
Custom validation uses Validator interface or custom constraint annotations. It integrates with Bean Validation API for complex validation rules.
@EnableAutoConfiguration configures application based on classpath. It processes auto-configuration classes and conditions for automatic setup.
HandlerMethodArgumentResolver customizes controller parameter resolution. It enables custom parameter handling and complex object binding.
Custom formats use Formatter interface or annotations. They enable type conversion and formatting for specific data types or patterns.
@Import brings external configurations into context. It supports regular @Configuration classes, ImportSelector, and ImportBeanDefinitionRegistrar.
SmartLifecycle manages component lifecycle phases. It enables ordered startup/shutdown and phase-based lifecycle management.
Custom endpoints extend WebMvcConfigurer or WebFluxConfigurer. They enable specialized request handling and custom API endpoints.
@EnableConfigServer sets up configuration server infrastructure. It manages externalized configuration with various backend stores.
ApplicationContextAware provides context access to beans. It enables accessing container resources and other beans programmatically.
Custom scoping requires scope implementation and registration. It manages bean lifecycles within custom-defined boundaries.
@EnableFeignClients configures declarative REST clients. It processes Feign client interfaces and manages client-side load balancing.
BeanNameAware provides bean name to instances. It enables beans to access their own names during initialization phase.