Learn to implement an asynchronous execution with automatic retry in a Spring application.
Also find me here:
Baeldung Editor
Ashley Frieze
I've been writing software since I was a kid, and have been doing it professionally since the days of dial-up internet. These days I'm a consultant, helping teams with full stack cloud projects in Java and TypeScript. When I'm not software engineering, I can be found performing as a stand-up comedian, or in musical theater.
Here's what I've reviewed (so far):
Baeldung on Java
- All
- Java (19)
- Spring Boot (15)
- Testing (14)
- Core Java (11)
- Spring (8)
- REST (8)
- Spring Cloud (7)
- Persistence (6)
- Spring Security (5)
- Spring Data (5)
- NoSQL (5)
- Java String (5)
- Java IO (5)
- Java Collections (5)
- Maven (4)
- Java Concurrency (4)
- JVM (4)
- Groovy (4)
- Web Services (3)
- Spring Web (3)
- Java Dates (3)
- IDE (3)
- Security (2)
- Logging (2)
- Java Web (2)
- Java Streams (2)
- Java Numbers (2)
- Java Array (2)
- Jackson (2)
- JSON (2)
- HTTP Client-Side (2)
- DevOps (2)
- Data (2)
- Cloud (2)
- XML (1)
- Spring Persistence (1)
- Spring MVC (1)
- Reactive (1)
- Networking (1)
- Java Map (1)
- Jakarta EE (1)
- JPA (1)
- Guava (1)
- Gradle (1)
Time Conversions Using TimeUnit
Filed under Java Dates
We look at how to use TimeUnit to convert durations between units and avoid creating our own hard-to-read math code.
What Is the .idea Directory?
Filed under IDE
IntelliJ IDEA stores its settings in the .idea directory. We look at what’s stored here and whether to share the contents via source control.
How To Manage Timeout for CompletableFuture
Filed under Java Concurrency
Explore different ways to manage timeouts with Java CompletableFuture.
Guide to the yield Keyword in Java
Filed under Core Java
Java’s new yield keyword makes it easier to provide a returned result from switch statements. We look at how it works and how it can help ensure we cover all possible cases.
Getting Started With Apache Pulsar and Spring Boot
Filed under Spring Boot
Pulsar is a high-throughput pub/sub system which aims to overcome Kafka’s limitations. We look at how to use it with Spring.
Metadata GC Threshold in Java
Filed under JVM
The Java Garbage Collector plays a part in managing the memory of the metaspace, where information about classes is stored. We look at tuning parameters to help the JVM manage our application.
Stateless Object in Java
Filed under Java
Java requires all code to be in classes. Sometimes we may need to create an object with no state in order to help achieve a design pattern. We look at stateless objects and how they function.
Setup Http Patch Request With OpenFeign
Filed under Spring Cloud
Spring Cloud OpenFeign makes it easy to write a client to REST APIs. We can use this for PATCH requests. We look at how this works and how to set it up to avoid common pitfalls.
Gray Box Testing Using the OAT Technique
Filed under Testing
Gray Box testing is a statistical technique that allows us to test a lot of edge cases without testing every single possible permutation of input. We look at how it works and how to implement it with parameterized tests in JUnit.
Different Dependency Version Declarations in Gradle
Filed under Gradle
When building with gradle we may wish to stay on the latest version of each of our dependencies. We look at a few ways we can achieve this.
Shared Secret Authentication in Spring Boot Application
Filed under Spring Boot, Spring Security
Private microservices may use a shared secret to protect their APIs from illegal access. We look at how to implement a simple token based security pattern based on a shared secret using Spring Security.
Send MultipartFile Request With RestAssured
When testing, we may wish to send uploads to endpoints that use Multipart data. We look at how RestAssured can help us with these tests and how to mock those services with Wiremock.
Scoped Values in Java 20
Filed under Java Concurrency
Scoped values is a new API in Java 20 that enables developers to store and share immutable data within and across threads. We look at how to use it and how it works.
Generating Time Based UUIDs
Filed under Java
Java has a built in UUID generator. We compare this to some other solutions which can be more secure or performant.
Loading Multiple YAML Configuration Files in Spring Boot
Filed under Spring Boot
Spring can load YML into memory for us, making it easy to inject data into our running application. We look at how to split that YML across multiple files, rather than keep it all in a single application.yml.
Integrate AWS Secrets Manager in Spring Boot
Filed under Spring Boot
AWS Secrets Manager is a good place to store credentials for databases or other services. We look at how to provide our Spring Boot application with secrets from Secrets Manager at runtime.
Run a Spring Boot Application in AWS Lambda
Filed under Cloud, Spring Boot
AWS has released a library to help convert a Spring Boot application into an AWS Lambda. We look at how to use this library and how to deal with long cold start times.
Cassandra – Object Mapping with DataStax Java Driver
Filed under NoSQL, Spring Data
There are a few ways to map objects and operations to Cassandra. We look at how to use the DataStax driver to achieve object mapping, queries and native functions.
Singleton Design Pattern vs Singleton Beans in Spring Boot
Filed under Spring Boot
Compare singleton beans with objects created using the singleton design pattern.
OpenTelemetry Setup in Spring Boot Application
Filed under Spring Boot, Spring Cloud
Deploying microservices can lead to challenges in tracing requests across those services. With OpenTelemetry we’re able to capture logs from independent services and use them to observe traces of entire requests. We look at how to achieve this in Spring.
Validating IPv4 Address in Java
Filed under Java Web
We may wish to validate IP addresses from our settings files or other inputs. We look at a few ways to do this using libraries and plain Java code.
Using and Testing Axon Applications via REST
Once we have the Axon framework in place, we can add REST APIs to it. We look at how to add these endpoints and how they’re unit tested.
HTTP Interface in Spring 6
Filed under Spring Web
Spring has a new web client builder that’s similar to OpenFeign, but is native to Spring. We look at how to build API clients with itm .
Fixing the No Main Manifest Attribute in Spring Boot
Filed under Spring Boot
We may sometimes get the No Main Manifest Attribute error when building our Spring Boot applications. We look at the root cause and how to fix it.
Running Multiple Thread Groups in JMeter
Filed under Java Concurrency, Testing
A Thread Group allows us to simulate a specific type of workflow. We can run Thread Groups in parallel, or sequentially. We look at how to achieve this in JMeter.
REST vs. GraphQL vs. gRPC – Which API to Choose?
Filed under REST, Web Services
REST, GraphQL, and gRPC are solutions to different problems when calling webservices. We look at how they differ and can be combined in our architecture.
Iterate Through Two ArrayLists Simultaneously
Filed under Java Collections
Java does not provide an explicit way to iterate over two lists at the same time. We look at some techniques and libraries that can help us correlate data between two collections according to index.
assertAll() vs Multiple Assertions in JUnit5
Filed under Testing
Normally a single assertion failure will stop a unit test. However, we can group assertions together, and report on their combined success or failure, using assertAll() within JUnit 5.
Log Properties in a Spring Boot Application
Filed under Logging, Spring Boot
For debugging purposes, it can be useful to list the application properties within a Spring Boot application. We look at a few techniques for outputting and filtering runtime properties.
TLS Setup in MySQL and Spring Boot Application
Filed under Spring Security
Learn how to enable a secure connection on a MySQL server.
Guide to MicroStream
Filed under NoSQL, Persistence
MicroStream is an alternative to a database engine. It allows for direct storage of Java objects with queries performed using stream-like APIs. We look at how this new technology can be used.
Difference Between Arrays.asList() and List.of()
Filed under Java Collections
Java provides some helper functions for us to build List objects from arrays. We look at how they work and the capabilities and limitations of the resulting List objects.
Propagating Exceptions With OpenFeign and Spring
Filed under Spring Boot
Let’s look at a few strategies for handling errors received during OpenFeign requests.
Use Cases for Static Methods in Java
Filed under Core Java
Java allows us to declare functions as static. We look at what this means, how static functions differ from others, and some common use cases for preferring static functions.
How to Split a Stream into Multiple Streams
Filed under Java Streams
Sometimes we need to process the elements of a stream in multiple ways. We explore a few options for splitting the stream, or running the stream over several terminal operations.
Setting Request Headers Using Feign
Filed under REST
OpenFeign is a library that helps us build clients to web services by expressing the contract in a Java interface. We look at how to include header values in our requests through the interface, with fixed and dynamic values, and how to handle cross-cutting concerns like authorization by using interceptors.
Check if a Character Is a Vowel in Java
Filed under Java String
If we need to classify a character as a vowel or consonant in English, then there are a few ways we can achieve this. We look at three possible solutions in Java and compare their performance and ease of use.
Posting with Java HttpClient
Filed under HTTP Client-Side
From Java 9 onwards, the new HttpClient API provides both a synchronous and asynchronous modern web client. We look at how it can be used to make requests.
Compile Multiple Java Source Files Using the Command Line
Filed under Java
We can use the javac tool to compile source files in Java. We look at how to use it for multiple source files and how to control which libraries are included and where the compiled code will be written.
Spark DataFrame
Filed under Data
Spark’s DataFrame component is an essential part of its API. It represents data in a table like way so we can perform operations on it. We look at the Java Dataset type, which is used to interact with DataFrames and we see how to read data from a JSON file and write it to a database.
List vs. ArrayList in Java
Filed under Java Collections
When using collections in Java it’s conventional to use the interface types for our variables and fields, rather than the concrete types. We look at the difference between these two approaches.
Spring Cloud – Disable Discovery Clients with Profiles
Filed under Spring Cloud
While Spring’s service discovery mechanisms can be very helpful we may wish to turn them off in certain environments. We look at how to achieve this with both properties files and Spring profiles.
Basic Authentication in JMeter
Filed under Testing
We can use JMeter to load test endpoints with Basic Authentication in a few different ways. We look at the simplest method of adding credentials directly to a header, along with how to provide a set of credentials from a data source.
Case Insensitive Sorting in MongoDB
Filed under NoSQL
MongoDB’s default lexical sorting may not be suitable for all purposes. Here we look at a couple of techniques for sorting to keep letters together even if they’re in a mix of upper and lowercase.
Make a Call to a GraphQL Service from a Java Application
Filed under Web Services
GraphQL is a standard for communicating with web services. We look at a few ways to access GraphQL endpoints from a Java application.
GraphQL vs REST
Filed under REST, Web Services
GraphQL and REST can be used to enable the same integrations between different parts of our systems. We compare the two approaches to see how they have benefits in different situations.
Hibernate Validator Annotation Processor in Depth
Filed under Persistence
When using the Java constraints library, it’s easy to make a mistake with an annotation and only find out about it at runtime. We look at the available annotation processor and how it can give us early feedback.
Get the Name of the Currently Executing Test in JUnit
Filed under Testing
Sometimes we need our unit tests to be able to access the name JUnit has allocated to them. This is especially useful when using name generators or parameterized tests. We look at how to solve this problem in both JUnit 4 and 5.
Running a TestNG Project From the Command Line
Filed under Testing
TestNG is a unit testing library which can be run via the IDE and build tooling. We look at how to run TestNG tests directly with the command line.
Generating a Java String of N Repeated Characters
Filed under Java String
Producing a string out of repeating a character or sequence can be done a variety of ways. We look at a few methods, and compare them for readability and efficiency.
Random Number Generators in Java 17
Filed under Java Numbers
Java 17 provides a large number of improvements to the generation of random numbers. We explore the new API and compare it with the original random number generators.
Getting a Bit at a Certain Position from Integral Values
Filed under Java
We may need to test whether the binary digits of a number are set. We explore how to do this for any digit in an integer, using some optimised binary maths as well as some simpler alternatives.
How to Get Response Body When Testing the Status Code in WebFlux WebClient
Filed under Reactive
Spring WebFlux client provides many ways to process the responses of our web requests. We look at a few techniques to process the response body, based on status code, using functional programming.
Solving the Hide Utility Class Public Constructor Sonar Warning
Filed under Java
We may produce utility classes with static methods in Java and then receive a warning from Sonar about the implicit public constructor. We look at how to handle this error and some alternative implementations for static modules.
Add an Image to a Cell in an Excel File With Java
Filed under Java IO
Apache POI allows us to build Excel spreadsheets from Java code. In this tutorial we look at the steps for adding images to our spreadsheets.
Assert That a Java Optional Has a Certain Value
Filed under Testing
We may need to write assertions on Optional values. We explore a few ways to do this, both with JUnit assertions and with the AssertJ library.
Spring Boot Startup Actuator Endpoint
Filed under Spring Boot
Spring Boot Actuator can help us understand where time is spent during application start up. We look at how to install it and use it to diagnose delays in initializing our Spring Boot application.
Deserialize Snake Case to Camel Case With Jackson
Filed under Jackson
By default, Jackson expects the field names in JSON to match the ones in our Java POJOs. As Java usually uses camel case field naming by convention, this makes it harder to deserialize snake case JSON. We look at some ways to configure our code so that we can load JSON with other field naming conventions.
Using Test Containers With Spring Data Cassandra
Filed under Spring Persistence, Testing
We can test our Spring Data integration with Cassandra by using Testcontainers. This starts a temporary instance of Cassandra to use during our tests. We investigate how to do this and configure spring during the test.
Saving Date Values in Spring Data Cassandra
Filed under NoSQL
Learn how to use Spring Data Cassandra to save date values and map them to Cassandra data types.
New Features in Java 16
Filed under Core Java
Java 16 brings a series of improvements to the language, including increments to records, sealed classes and switch statements. We review some of the new features as well as looking at some capabilities that are going away.
Fixing the “Declared package does not match the expected package” Error
Filed under Java
If the package name of a java file does not match its location on the file system, we’ll get an error. We look at a few common causes for this and how to fix it.
Find the IP Address of a Client Connected to a Server
Filed under Networking
We can find the address of a client connected to our application by using the APIs within the java.net package. We look at establishing a TCP socket and understanding its properties.
Spring @EnableWebSecurity vs. @EnableGlobalMethodSecurity
Filed under Spring Boot, Spring Security
Spring Security in Spring Boot allows a couple of different approaches for setting access rights for our endpoints. We explore both the standard web security module and the JSR–250 approach here.
Inserting Delays Between Requests in Apache JMeter
Filed under Testing
To simulate user activity, we often need to add timing to our JMeter configuration. We explore how to build a test plan with gaps between actions.
Convert a String to Camel Case
Filed under Java String
Camel case text conversion can be achieved by using regular expressions, or via some library functions. We look at a couple of implementations we can add to our own code, and a couple of examples from libraries.
Plugin Management in Maven
Filed under Maven
Plugin management allows us to configure how plugins work across multi-module maven builds. We look at how this can be used and configured.
Tiered Compilation in JVM
Filed under JVM
The JVM’s just in time compiler employs multiple techniques to optimize our software as it runs. We explore the various tiers and how they affect startup performance and continued optimization.
Logical vs Bitwise OR Operator
Filed under Java
Java supports two variations of OR with different operator precedence and runtime behaviour. We explore how logical OR short-circuits and how bitwise OR applies to numbers and boolean values.
The settings.xml File in Maven
Filed under Maven
We can configure maven via the settings.xml file. We look at some common use cases and configuration options.
Find All Numbers in a String in Java
Filed under Java String
We can use regular expressions to count occurrences of numbers in a String in Java. We look at finding numbers of various formats, extracting and converting them back into numeric form, as well as counting digits.
Guide to Retry in Spring WebFlux
Filed under Spring Web
Cloud applications should be built for resilience. The Spring WebClient provides a few techniques out of the box for retrying failed connections. We look at how to produce retry behaviour with a few additional configuration options.
What Are Compile-Time Constants in Java?
Filed under Core Java
The Java compiler is able to pre-calculate certain values for us at compile time. This allows us to use some variables with expressions that must be constant, and leads to some runtime efficiencies.
Solving Spring’s “not eligible for auto-proxying” Warning
Filed under Spring
When setting up a bean post-processor, we can get a warning from Spring; “not eligible for auto-proxying”. We explore the cause of this issue and how to resolve it.
Decode a JWT Token in Java
JWT is used to provide a user’s credentials to a web service. We look at how to read the contents of a JWT and verify its authenticity.
Invoking a Private Method in Java
Filed under Java
We sometimes need to access private methods from our code, especially our test code. In this tutorial we cover a couple of ways to make private methods accessible.
Override Maven Plugin Configuration from Parent
Filed under Maven
While we want to modularise our maven file to avoid repetition, sometimes it’s necessary to provide specific variations for child modules. Here we explain how the various tiers of a maven file can be combined.
Prevent Cross-Site Scripting (XSS) in a Spring Application
Filed under Spring Security
When writing a web service in Spring we need to create a custom filter in order to protect our services from cross-site scripting attacks. We explore how to achieve this using ESAPI and Jsoup.
Using the Map.Entry Java Class
Filed under Java Map
We often use maps to store a collection of key-value pairs. We explore the Entry objects inside a map and how to make the most of them.
Is Java a Compiled or Interpreted Language?
Filed under Java
Java provides the speed of a compiled language with the portability of an interpreted language. We investigate how the JVM and JIT compiler work, and how to classify Java as a language.
Java File Separator vs File Path Separator
Filed under Java IO
To make our code portable between operating systems, we need to handle the directory and path separator characters correctly. We look at a few ways that Java can help use the correct characters for the host operating system.
New Features in Java 11
Filed under Core Java
Java 11 brings new features, including convenience methods in the standard libraries and the integration of the new HTTP Client. We review these and other improvements.
Get list of JSON objects with Spring RestTemplate
Filed under HTTP Client-Side, JSON, Spring
Spring RestTemplate can convert a JSON array to a variety of Java types. We look at the options and how to produce a type-specific list.
Configuring a Project to Exclude Certain Sonar Violations
Filed under DevOps
For some analyses, SonarQube needs some exclusions added to avoid false positives. We investigate a few ways to configure it.
Writing byte[] to a File in Java
Filed under Java IO
When we need to write an array of bytes to a file in Java, there are a few options. We can use either the built-in APIs or a few common libraries.
How to Access an Iteration Counter in a For Each Loop
Filed under Java, Java Collections
Java’s for each loop does not provide an iteration counter. There are a few ways we can iterate over both the item and its index.
The Capacity of an ArrayList vs the Size of an Array in Java
Filed under Java Array
The capacity of an ArrayList functions differently to the size of an Array. We explore the differences and when it’s a good idea to set an ArrayList’s size.
Creating a Generic Array in Java
Filed under Java Array
The loose types of Java generics are hard to coerce into the strong types of Java arrays. We explore the problem and some common solutions.
Storing Files Indexed by a Database
Filed under Spring Data
Learn how to store files inside a databases as Large Objects, or how to use a database as an index of a filesystem.
How to Turn Off Swagger-ui in Production
The Swagger UI can be very helpful during development, but may be a security risk in production. We look at how to ensure it isn’t left accidentally available.
Using application.yml vs application.properties in Spring Boot
Filed under Spring Boot
Spring Boot supports both .properties and YAML. We explore the differences between injecting properties, and how to provide multiple configurations.
Finding the Differences Between Two Lists in Java
Filed under Java Collections
We investigate how to finding elements present in one list, but not in another, including lists with multiple copies of the same element.
Liskov Substitution Principle in Java
Filed under Java
The L in SOLID, the Liskov Substitution Principle helps structure object oriented design. We also explore how it supports the Open/Closed Principle.
How to Resolve a Version Collision of Artifacts in Maven
Filed under Maven
Multi module maven projects can experience difficulties at compile time and runtime with multiple library versions. We learn how to control the versions used.
How to Count the Number of Matches for a Regex?
Filed under Java
Regular expressions can help us with text processing. Here we explore how to count the number of matches of a regular expression in some text.
Retrying Failed Requests with Spring Cloud Netflix Ribbon
Filed under Spring Cloud
With a network of webservices in our cloud applications, having a sophisticated fallback and retry mechanism can increase stability. We explore Netflix Ribbon.
Foreign Memory Access API in Java 14
Filed under Core Java
Java 14 brings in a new API to wrap accessing memory managed outside of the JVM. Here we explore the need for the API and how it works.
Generate Database Schema with Spring Data JPA
Filed under Spring Data
JPA provides a standard for generating DDL from our entity model. Here we explore how to do this in Spring Data and compare that with native Hibernate.
Quick Guide to Spring Cloud Circuit Breaker
Filed under Spring Cloud
Circuit Breakers allow errors to be handled gracefully. Spring Cloud now supports multiple circuit breaker libraries with the same interface.
Add BigDecimals using the Stream API
Filed under Java Numbers
While the streams API provides a useful way to calculate the sum of some numeric types, BigDecimal is not support. Here we learn how to calculate sums with reduce.
Quick Guide to Hibernate enable_lazy_load_no_trans Property
Filed under Persistence
Lazy loading can reduce unnecessary database traffic, but it requires all lazy-loaded object navigation within the session. Hibernate provides a workaround.
IntelliJ – Cannot Resolve Spring Boot Configuration Properties Error
IntelliJ can provide autocomplete and context help for custom properties, but we need to make some additional configuration to our project to enable that.
Compare Two JSON Objects with Gson
Filed under JSON
Comparison of JSON in its string representation is often less effective than comparing it semantically. Here we use Gson to load the JSON and compare the data.
Delete Everything in Redis
Filed under Cloud, NoSQL, Persistence
We may need to clear a Redis cache when its data becomes out of date. We explore how to do this with both the command line and Java client.
Asynchronous HTTP Programming with Play Framework
The Play Framework provides an asynchronous HTTP client to make calls to web services in the background while doing other work. We explore how to use it.
Configuring Retry Logic in Spring Batch
Filed under Spring
Spring Batch allows us to set retry strategies on tasks so that they are automatically repeated when there is an error. Here we see how to configure it.
Guide to @CurrentSecurityContext in Spring Security
Filed under Spring Security
Reading from the Spring Security Context can require a bit of boilerplate code. With the @CurrentSecurityContext annotation we can inject the values we need.
Generating Barcodes and QR Codes in Java
Filed under Java
Java has a few libraries we can call on to generate barcodes or QR codes. Here we see how to use them and integrate them into a web application.
How to Return Multiple Values From a Java Method
Filed under Java
Some programming languages provide easy ways to return multiple values from a method. In Java, there are a few similar options, depending on the types.
Guide to the Java finally Keyword
Filed under Core Java
Java’s finally keyword is helpful for clean-up operations around code that may throw errors. We explore how it works and when it can have unexpected behaviour.
Using the Not Operator in If Conditions in Java
Filed under Core Java
Inverting logical expressions can make your code clearer, and is an important part of using Java. Here are some tricks to master and pitfalls to avoid.
Check if Two Strings Are Anagrams in Java
Filed under Java String
We may wish to detect whether Strings contain anagrams of each other. Here we explore a few algorithms, with different programming and execution complexity.
WebSockets with the Play Framework and Akka
Filed under Java Web
WebSockets allow continuous communication between a client app and its server. This can be built with reactive streams in Akka and the Play Framework.
Common Concurrency Pitfalls in Java
Filed under Java Concurrency
There is plenty to catch us out when we write multi-threaded or concurrent code within Java. Here we explore some common problems and their solutions.
What Is a Pojo Class?
Filed under Java
Knowing the difference between a POJO and a JavaBean may be the key to unlocking the potential of our classes in core Java.
Determine the Execution Time of JUnit Tests
Filed under Testing
Knowing the time taken by our automated tests can be helpful in pin-pointing issues, or optimising our builds. There are a few ways to view our test execution reports.
Parsing Command-Line Parameters with JCommander
Filed under Java
JCommander takes on all the complexity of parsing and validating parameters for our command line applications. We explore all of its core features.
Customizing the Result of JPA Queries with Aggregation Functions
Filed under JPA, Spring Data
Spring Data JPA has some useful tricks for mapping the results of aggregation queries to custom objects, rather than the default object arrays.
Java ‘protected’ Access Modifier
Filed under Core Java
The protected modifier helps Java classes to encapsulate their implementation and also share it with related types. Explore how this modifier works in practice.
Digital Signatures in Java
Filed under Security
Java provides support for digital signature via the JCA APIs. See how to digitally sign and verify messages with public/private key cryptography.
Hibernate @WhereJoinTable Annotation
Filed under Persistence
Hibernate allows querying according to columns within the relation table in a many-to-many relationship. This is achieved with the WhereJoinTable annotation.
Mocking a WebClient in Spring
Mocking the fluent Spring WebClient interface for testing is possible but hard work. MockWebServer is an easy to use alternative.
Ignoring Unmapped Properties with MapStruct
Filed under Data
MapStruct allows us to copy between Java beans. There are a few ways we can configure it to handle missing fields.
Unmarshalling Dates Using JAXB
Filed under Java Dates, XML
JAXB has basic support for reading data formats built in. Let’s extend this functionality to support unconventional formats and the Java 8 Date/Time types.
How to Avoid the Java FileNotFoundException When Loading Resources
Filed under Java IO
Java programs cannot easily load files once they have been compiled into the resources of a JAR or WAR file. Here’s how to load resources reliably.
@Timed Annotation Using Metrics and AspectJ
Filed under Logging
We look at how to add lightweight timing instrumentation to an app using a combination of Metrics and AspectJ, making it as simple as adding @Timed to a method.
Java Naming and Directory Interface Overview
Filed under Jakarta EE
We investigate the fundamentals of the JNDI API, which allows the configuration of external resources to be managed outside of our apps.
@TestInstance Annotation in JUnit 5
Filed under Testing
JUnit 5 allows us to customise the lifecycle of our test objects to share resources and state between tests. We investigate the @TestInstance annotation.
Functional Controllers in Spring MVC
Filed under Spring MVC
Spring MVC controllers can now be written in a new functional style. Explore this new pattern, bringing the benefits of functional programming to blocking code.
Guide to Spring Cloud Stream with Kafka, Apache Avro and Confluent Schema Registry
Filed under Spring Cloud
Make Spring Cloud support Kafka with the Confluent standard components and approach, including Avro, the Schema Registry and the standard binary message format.
Adding Copyright License Header for Java Source Files in Eclipse
Filed under IDE
Putting copyright messages at the top of source files is easy with these tools in the Eclipse IDE.
Guide to Java BiFunction Interface
Filed under Core Java
Learn some common patterns for Java functional interfaces that take two parameters.
Guide to MapDB
Filed under Persistence
Learn about MapDB, a lightweight persistence library which provides collection APIs to store and retrieve data.
How to Break from Java Stream forEach
Filed under Java Streams
Java Streams are often a good replacement for loops. Where loops provide the break keyword, we have do something a little different to stop a Stream.
Load a Resource as a String in Spring
Filed under Spring
Learn how to inject the contents of a resource file into our beans as a String, with Spring’s Resource class making this very easy.
Ratpack with Groovy
Filed under Groovy
Ratpack is a set of lightweight Java libraries for building scalable non-blocking HTTP applications. We explore building a Ratpack service in Groovy.
Guide to Java FileChannel
Filed under Java IO
Find out how to use the Java NIO FileChannel APIs to read and write files more efficiently.
Java 9 Migration Issues and Resolutions
Filed under Java
Find out how to solve common issues related to the Java module system when migrating an existing application to Java 9.
How to Configure Spring Boot Tomcat
Filed under DevOps, Spring Boot
Learn how to reconfigure the embedded Tomcat server in Spring Boot for some common use cases.
Setting the Log Level in Spring Boot When Testing
Filed under Spring Boot, Testing
For when you need to diagnose test failures by examining more detailed log output, here is how to reconfigure the logging in Spring apps at test time.
Spring Data JPA and Null Parameters
Filed under Spring Data
Learn different ways to use null parameters with Spring Data JPA queries, including how to make query parameters optional.
Guide to Guava Multiset
Filed under Guava
Store counts of duplicates in a set using Guava Multiset. See how to use this powerful part of the Guava library in single and multi-threaded applications.
Compressed OOPs in the JVM
Filed under JVM
Find out how to tune the JVM to use memory more efficiently and address 32Gb of heap even in a 32-bit system.
Cannot Reference “X” Before Supertype Constructor Has Been Called
Filed under Java
Find out why the compiler will not let you call an instance method too early in a constructor and what you can do to fix it.
Finding Elements in Collections in Groovy
Filed under Groovy
Find out how Groovy simplifies checking for elements and finding them in several types of collections.
Closures in Groovy
Filed under Groovy
Explore the concept of closures in Groovy, a key feature of this dynamic and powerful JVM language.
Currying in Java
Filed under Core Java
Learn how to improve your functional programming with chains of single parameter function calls. Currying turns multiple parameters into a fluent style.
Introduction to Spring Cloud OpenFeign
Filed under Spring Cloud
Feign makes writing web service clients easier with pluggable annotation support, which includes Feign annotations and JAX-RS annotations.
Guide to I/O in Groovy
Filed under Groovy
Have a look at Groovy’s support for I/O operations and the extensions to Java’s I/O functionality.
Native Memory Tracking in JVM
Filed under JVM
Learn about native memory allocation in the JVM and how to track it.
Jackson Date
Filed under Jackson, Java Dates
How to process dates with Jackson – marshalling and unmarshalling these to and from JSON.