How to Implement Aspect-Oriented Programming (AOP) in Spring
Add aspect-oriented programming to a Spring app with aspects, advice and pointcuts, and see why self-invocation and final methods are not advised.
2,886 posts about Java: questions with answers, tutorials and articles, newest first.
Add aspect-oriented programming to a Spring app with aspects, advice and pointcuts, and see why self-invocation and final methods are not advised.
@EnableAspectJAutoProxy activates @Aspect-based AOP in Java-configured Spring apps. See how to set it up, write pointcuts, order aspects and avoid common pitfalls.
Add created and modified audit fields in Spring Data JPA with AuditorAware and Spring Security, and use Hibernate Envers when you need full revision history.
Tune the pool, retry only transient failures and map the rest to a clear 503 response when Spring cannot reach the database.
JDBC gives you direct control over SQL, while JPA maps objects to tables for you. Compare them with code examples and learn when to choose each.
Map query results to objects in Spring JdbcTemplate using a RowMapper lambda, a reusable class, DataClassRowMapper for records, or a ResultSetExtractor for joins.
Propagation.NESTED runs a method inside the caller's transaction using a savepoint, so a failure can be rolled back without losing the rest of the work.
JdbcTemplate runs SQL without the JDBC boilerplate. See queries, RowMapper, batch updates, JdbcClient and transaction handling in Spring.
Enable Hibernate JDBC batching, save in chunks and clear the persistence context. Learn when JdbcTemplate or Spring Batch is the better fit for bulk work.
It marks a transaction as read-only so Spring, Hibernate and the database can skip work like dirty checking. It is a hint, not a guard.
Build dynamic JPA filters with Spring Data Specifications: reusable predicates, allOf and anyOf, pagination, joins and the static metamodel for type safety.
Specification represents a reusable query condition in Spring Data JPA. See how JpaSpecificationExecutor, and, or and not build dynamic, paged searches.
Build dynamic JPA queries with CriteriaBuilder using optional predicates, joins, paging and projections, with parameter binding and a type-safe metamodel.
The Criteria API builds type-safe, dynamic JPA queries from Java objects. See CriteriaBuilder, the static metamodel and Spring Data Specifications.
Keep memory flat on big tables with pagination, streaming, batched writes, DTO projections and Spring Batch jobs in Spring Boot 3.
Pass a Pageable built with PageRequest.of(page, size, Sort) to a repository method returning Page. Spring Data adds ORDER BY, LIMIT and OFFSET for you.
Use Page and Pageable in Spring Data JPA to return paginated, sorted results with total counts, and learn when Slice or keyset scrolling is a better fit.
Understand what Pageable does in Spring Data, how PageRequest, Page and Slice fit together, and how to bind it from HTTP request parameters.
Use Pageable, Page and Slice in repository methods, write count queries for joins, project columns and scroll by keyset.
Return a ResponseEntity of Resource with the right headers to serve file downloads in Spring, and protect against path traversal and oversized responses.