Log4j 2 vs Logback: Differences and How to Choose
Logback is the SLF4J-native default in Spring Boot, while Log4j 2 excels at async logging. Compare features, config and performance, then choose.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
Logback is the SLF4J-native default in Spring Boot, while Log4j 2 excels at async logging. Compare features, config and performance, then choose.
MongoTemplate wraps the MongoDB driver with typed insert, find, update and remove methods. Learn how to use Query, Criteria and Update, and when it beats a repository.
MongoDB relationships use embedded documents or references. Learn when to choose each, with Spring Data MongoDB, @DocumentReference and $lookup.
Set up a custom Java logger with java.util.logging or SLF4J and Logback, including file rotation, formatting, MDC and production logging practices.
@Document maps a Java class to a MongoDB collection in Spring Data MongoDB. See how to name collections, use records, add indexes and avoid common mistakes.
logback.xml defines where Spring Boot logs go, how they look and which levels apply. See a rolling file setup and why logback-spring.xml is usually better.
Extend MongoRepository for a @Document class, then use derived query methods, @Query, paging and MongoTemplate. Covers setup with and without Spring Boot.
Configure Spring Boot log levels with logging.level properties, groups and profiles, then change them at runtime through Actuator or LoggingSystem.
It provides the MongoDB driver, Spring Data repositories and an auto-configured MongoTemplate for Spring Boot applications.
Lombok's @Slf4j adds a static final SLF4J logger named log to your class at compile time. See how it works, how to configure it and which alternatives exist.
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.