This module contains practical examples of common Spring Boot development scenarios.
- Location:
src/main/resources/application.propertiesandapplication-development.properties. - Approach: Use a common properties file for shared configuration and profile-specific files (e.g.,
-development,-production) for environment-dependent settings. Active profiles are set viaspring.profiles.active.
- Location:
com.froyo.mlt.controller.InvoiceV1Controller. - Approach: Leverage URL versioning (e.g.,
/api/v1/invoices) to ensure backward compatibility as the API evolves.
- Location:
com.froyo.mlt.service.ProductService. - Approach: Use
@CachePutto update the cache synchronously whenever the database is modified, ensuring the cache always reflects the latest state.
- Location:
com.froyo.mlt.controller.GlobalReactiveExceptionHandler. - Approach: Use
@ControllerAdvicein a Spring WebFlux application with@ExceptionHandlerto catch and process asynchronous errors gracefully.
- Location:
com.froyo.mlt.repository.OrderRepository. - Approach: Use the
@Queryannotation with JPQL or native SQL to implement complex data retrieval needs that involve multiple criteria, sorting, and pagination.
- Location:
com.froyo.mlt.service.OrderMessagePublisher. - Approach: Integrate Spring Cloud Stream (with Kafka or RabbitMQ) to enable efficient asynchronous communication and coordination between microservices, enhancing scalability and responsiveness.
- Location:
com.froyo.mlt.repository.InventoryRepository. - Approach: Use
@Lock(LockModeType.PESSIMISTIC_WRITE)to manage concurrent access to database entities, ensuring that update operations are serialized to prevent data inconsistencies.
- Location:
com.froyo.mlt.config.SecurityConfig. - Approach: Extend
WebSecurityConfigurerAdapterand override theconfigure(HttpSecurity http)method to define authorized/unauthorized access paths and security filters.
- Location:
com.froyo.mlt.model.FinancialAccount. - Approach: Implement optimistic locking by adding a
@Versionfield to the entity. This prevents the "lost update" problem in concurrent environments without the overhead of heavy database locks.
- Location:
com.froyo.mlt.service.StockMarketService. - Approach: Use the
@Asyncannotation to offload time-consuming tasks to separate threads, preventing performance bottlenecks in the main application flow and ensuring a responsive user experience.