How do you configure different cache providers in Spring?
Set up Spring caching with @EnableCaching and configure Caffeine, Redis, Ehcache 3 via JCache or the default provider in Spring Boot 3.
2,886 posts about Java: questions with answers, tutorials and articles, newest first.
Set up Spring caching with @EnableCaching and configure Caffeine, Redis, Ehcache 3 via JCache or the default provider in Spring Boot 3.
@CacheEvict removes entries from a Spring cache after data changes. See key-based and allEntries eviction, beforeInvocation and common pitfalls.
Use @CacheEvict, @CachePut and a TTL to keep Spring caches consistent with your data. Covers keys, allEntries, programmatic eviction and common pitfalls.
@CachePut updates a Spring cache every time a method runs, keeping reads fresh after writes. See examples, attributes and how it differs from @Cacheable.
Enable caching with @EnableCaching and declare a CacheManager bean. Examples cover in-memory, Caffeine, Redis and JCache or Ehcache 3 providers.
Spring rolls back only on unchecked exceptions by default. rollbackFor extends rollback to checked exceptions such as IOException.
Annotate Spring service classes or methods with @Transactional to run each business operation in one transaction. Covers rollback, propagation and pitfalls.
Propagation.REQUIRED, the default, joins an existing transaction or starts a new one, so related service calls commit or roll back together.
DataSourceTransactionManager provides local JDBC transactions for a single DataSource in Spring. See configuration, @Transactional use and its limits.
Choose and configure the right Spring PlatformTransactionManager for JDBC, JPA or JTA, and set up several managers for several databases.
@Transactional is declarative and proxy-based; TransactionTemplate gives explicit control. See examples, a comparison table and when to use each.
Spring wraps beans in proxies where TransactionInterceptor manages transactions. Learn pointcut advisors, advice ordering, and when AspectJ mode is needed.
@EnableTransactionManagement activates @Transactional support through proxies. Covers attributes, Spring Boot auto-configuration, rollback rules and pitfalls.
@AfterThrowing runs Spring AOP advice when an advised method throws an exception, ideal for logging and alerts. See syntax, examples and its limits.
Use @AfterThrowing to log or alert on failures and @Around to translate or recover from exceptions without touching business code.
@AfterReturning runs advice after a method returns normally and can read its result. See pointcut syntax, the returning attribute and proxy limits.
Write @Around advice in Spring AOP to wrap method calls for timing, caching and retries, and avoid the proxy pitfalls that stop advice from running.
@Before runs advice just before a matched Spring bean method. See pointcut syntax, JoinPoint arguments, ordering with @Order and when to use @Around instead.
Define Spring AOP pointcuts with @Pointcut and execution expressions, reuse them across advice, and avoid common proxy pitfalls like self-invocation.
@Aspect marks a class as a Spring AOP aspect for logging, security or transactions. Learn how to set it up, the advice types and its proxy limits.