How do you implement Spring Boot with MongoDB for database access?
A complete Spring Boot and MongoDB CRUD layer: document mapping, MongoRepository with paging, DTO records, validation and ProblemDetail error responses.
2,886 posts about Java: questions with answers, tutorials and articles, newest first.
A complete Spring Boot and MongoDB CRUD layer: document mapping, MongoRepository with paging, DTO records, validation and ProblemDetail error responses.
Spring Boot uses SLF4J with Logback by default. Configure levels, files, JSON output and profiles with logging properties or logback-spring.xml.
Spring Boot configures transactions automatically, so @Transactional on a service method is enough. See rollback rules, Boot properties and pitfalls.
Log4j 2 is Apache's configurable Java logging framework. Learn its structure, configuration, SLF4J and Spring Boot integration, and the security lessons of Log4Shell.
Spring Boot logs through SLF4J and Logback by default. Learn to log from services, configure levels and files, use structured JSON and switch to Log4j 2.
Use SessionCallback for explicit MULTI/EXEC or enable transaction support on RedisTemplate and use @Transactional. Redis queues commands and never rolls back executed ones.
Practical rules for fast, reliable Java unit tests with JUnit 5, AssertJ and Mockito, with runnable examples for each practice.
Add spring-boot-starter-test, then choose between plain unit tests, @SpringBootTest and slice tests such as @WebMvcTest and @DataJpaTest for fast, reliable suites.
@RedisHash marks a class as a Redis hash entity in Spring Data Redis. Learn how keys, ids, expiry and indexes work, with repository examples.
@EnabledIf runs a JUnit 5 test only when a condition method returns true. See how to write the method, share it across classes and avoid the Spring variant trap.
Wait on a real completion signal and bound it with a timeout. See CompletableFuture, @Async, @Timeout and Awaitility examples for reliable JUnit 5 async tests.
@Timeout fails a JUnit 5 test, lifecycle method or class of tests that exceeds a time limit, protecting builds from hangs and deadlocks.
Benchmark Spring code with JMH and measure live latency with Micrometer and Actuator, with warm-up, forks and result-quality tips.
Create, read, update and delete Redis data in Spring Boot with CrudRepository and RedisTemplate, including TTLs, JSON serializers and the cache abstraction.
RedisTemplate gives Spring applications a typed, thread-safe API for Redis data structures, serialization, pipelining and transactions.
Configure RedisTemplate and StringRedisTemplate in Spring Boot with correct serializers, TTL and examples for strings, lists, hashes and pipelines.
The spring-boot-starter-data-redis dependency adds Spring Data Redis and a Redis client, and auto-configures templates for caching, data storage and messaging.
Use Redis as a Spring Boot cache with @Cacheable and TTLs, then store entities with @RedisHash repositories and avoid common caching mistakes.
Learn the ways to write custom queries in Spring Data JPA: @Query, native SQL, derived methods, @Modifying updates and dynamic Specifications.
Pageable carries page number, size and sort; Page returns the content with total counts. See repository, controller and performance examples.