This post shows how to implement the Observer Design Pattern using the facilities available from Spring Application Events. More importantly, it shows how to publish and consume custom application events in Spring Boot. Observer Design Pattern – Publish And Consume
Mock Method To Return Different Values in Mockito
This post shows how to mock a method that returns unique values for different arguments in Mockito. For example, the return values vary according to the method argument. Sample Codes To Mock Suppose we have the following Java classes. The
Tomcat 9 and Up: JDBC Realm For Basic HTTP Authentication
It is incredible how we can modify Tomcat to help hasten the development. This post will demonstrate how to use Tomcat JDBC Realm, which uses an RDBMS for Basic HTTP Authentication. This could cut down development time and effort for
Java Web Application BASIC Authentication in Tomcat
The fastest way to configure authentication in Tomcat is Basic Authentication. However, it is one of the weakest forms of authentication, and we should not use it in real-life applications. Although we should not use Basic Authentication, it is still
How To Use WebFlux with Spring Boot
Using WebFlux with Spring Boot is straightforward and may not require changes when moving from Spring MVC. We will still use the same set of annotations like RestController and RequestMapping, to name a few. However, we use WebFlux to tap
Headstart Framework: Flyway and Supported Databases
We have designed the Headstart framework to be database-agnostic to support major database products with the help of Flyway. To achieve this database agnosticism, Headstart uses Spring Data/Hibernate but relies on migration scripts for creating database tables. We run these
The Number of Entities In a Hibernate Persistence Context
One of my worries with Hibernate was the number of entities accumulating in a Persistence Context. If I were not careful, my codes could potentially store thousands of entities in a Persistence Context. Worse, these objects could stay in memory
File Compression in Java with Apache Commons Compress
Apache Commons Compress can be downloaded from http://commons.apache.org/compress/
How To Use Java 8 Stream Reduce Example
This post shows how to use Java Stream Reduce with example codes. The idea of the reduce operation is the generation of a single result from a collection of values or objects. It is similar to the min and max operations
iReport 2.0.0 Page Numbers and Page Count
This post shows how to create a jasper report using iReport that displays page numbers and page count, e.g., 1/10. Moreover, the iReport will show the page numbers and page count on top of the pages. iReport 2.0.0 and other