Learn how to prevent UnexpectedRollbackException in Spring by using separate transactions or TransactionTemplate for reliable audit logging.
Also find me here:
Baeldung Author
Emanuel Trandafir
I'm Emanuel Trandafir, a passionate Java developer eager to explore and share insights on diverse programming paradigms, tools, and practices. I actively encourage my readers to join me in meaningful discussions, allowing us to learn from each other's perspectives. Beyond work, I love staying active through sports, hiking, and traveling, and I've recently switched from long-distance running to the thrill of rock climbing.
Here's what I've written (so far):
Baeldung on Java
- All
- Testing (10)
- Data (7)
- Architecture (7)
- Reactive (5)
- Spring WebFlux (4)
- Spring Data (4)
- Persistence (4)
- Spring Boot (3)
- Spring (3)
- Maven (3)
- Java Streams (3)
- Java Concurrency (3)
- Docker (3)
- Java (2)
- Web Services (1)
- Spring Web (1)
- Spring AI (1)
- Java Dates (1)
- Java Collections (1)
- Jackson (1)
- JSON (1)
- DevOps (1)
- Core Java (1)
- Artificial Intelligence (1)
How to Unit Test Micrometer
Filed under Testing
Unit testing metrics is crucial for ensuring that our application correctly tracks performance data and business metrics. By using Micrometer’s SimpleMeterRegistry, we can create isolated tests that verify our metrics collection without requiring a full Spring context. When it comes to integration tests, we need to reset the MeterRegistry to perform assertions on it during our @SpringBootTests.
Tagging Patterns for Micrometer Metrics
In this article, we explore Micrometer metrics with a focus on tagging. We use Micrometer in a Spring Boot application and apply various patterns to create simple metrics, such as counters and timers.
We’ll start by using Micrometer’s Builder API to create meters with variable tag values. Additionally, we’ll look at MeterProviders as an alternative that allows us to avoid potential performance issues. We’ll also use Spring AOP and Micrometer-specific annotations to record method invocations in a declarative manner.
Implementing CQRS with Spring Modulith
Filed under Architecture, Spring
Let’s take a fresh look at the CQRS pattern, exploring its benefits and trade-offs in a modular Spring Boot application. We’ll use Spring Modulith to structure our code into clearly separated modules and to enable asynchronous, event-driven communication between them.
This approach is inspired by our colleague Gaetano Piazzolla’s article, where he demonstrates CQRS with Spring Modulith in a product catalog. Here, we’ll adapt the same ideas to a movie ticket booking system and keep the two sides in sync via domain events.
How to Fix Unknown Magic Byte Errors in Apache Kafka
Filed under Data, Spring Boot
“Unknown magic byte” error and other deserialization issues can arise when consuming Avro messages in Kafka. Spring Kafka’s ErrorHandlingDeserializer and publishing to a DLQ topic can help manage poison pill messages like these, ensuring the consumer continues processing without getting stuck.
Transactional Messaging for Microservices Using Eventuate Tram
Filed under Architecture, Data
It’s challenging to maintain data consistency between database operations and messaging. We can make it simpler with the transactional outbox pattern and Eventuate Tram.
Micrometer Observation and Spring Kafka
Filed under Data
Explore the monitoring capabilities provided by Spring Kafka using Micrometer and Spring Boot Actuator. Take a look at the native metrics exposed by Apache Kafka for both producers and consumers, which offer valuable insights into performance, throughput, errors, and latency and those augmented by Spring.
Mocking JDBC for Unit Testing
Filed under Persistence, Testing
Testing code that uses JDBC objects to interact with the database raises important questions about mocking. It’s tempting to use Mockito to stub all the java.sql objects involved in acquiring a JDBC Connection, creating a Statement, executing a query and retrieving the data from the ResultSet. This comes with its own set of problems, though.
Generate Avro Schema From Certain Java Class
Although not the standard workflow, it can be handy to understand how one would create an Avro schema from a set of Java classes. It turns out we can use the Avro Reflection API or Jackson to do the trick.
Baeldung on Kotlin
- All
- Testing (1)
- Kotlin Strings (1)
- Kotlin Numbers (1)
- Kotlin Basics (1)
- Kotlin Arrays (1)
A Guide to Property-Based Testing in Kotlin
Filed under Testing
Learn about property-based testing in Kotlin.
Convert an Array to a String
Filed under Kotlin Arrays, Kotlin Strings
Learn how to convert an Array’s content to a String in Kotlin.
The ..< Operator for Open-ended Ranges in Kotlin
Filed under Kotlin Basics
Learn about the new Kotlin operator
Converting an Int? to an Int in Kotlin
Filed under Kotlin Numbers
Learn how to extract a value of a nullable variable.
Baeldung on SQL
- All
- Database Concepts (1)
Multiple Indexes vs. Multi-Column Indexes
Filed under Database Concepts
Explore database indexes, focusing on the differences between individual and composite indexes.