In this post under MapStruct, I will show with example how to add custom mapping methods if the out of the box generated mapping methods aren’t sufficient. For our example I will have the following pojo classes Person package package29; public class Person { private int id; private String name; private Address address; //Removed getter…… Continue reading Adding custom mapping method to Mapper interface
Month: September 2025
CollectionUtils retainAll method
In this post under Apache Collections, I will show with example the purpose of “retainAll” method under “CollectionUtils” class. The “retainAll” method takes two collections say “collection1” and “collection2” as arguments and returns a new collection. The new collection will only contain elements that are present both in “collection1” and “collection2”. Lets see a main…… Continue reading CollectionUtils retainAll method
Using Generics as Autowiring Qualifiers
In this post under Spring Core, I will show with example how Spring uses generics information when autowiring generic beans annotated with “@Qualifier” annotation. For our example I will create an generic interface “Store” as shown below Store interface package core.package47; public interface Store<T> { public void display(); } This generic interface has two implementations…… Continue reading Using Generics as Autowiring Qualifiers
PoolUtils synchronizedPooledFactory
In this post under Apache Pool, I will show with example how to create a synchronized object pool factory. Below is the complete main class for your reference Main class package package17; import org.apache.commons.pool2.PoolUtils; import org.apache.commons.pool2.PooledObjectFactory; public class StringBufferPoolExample17 { public static void main(String[] args) { StringBufferPooledObjectFactory stringBufferPooledObjectFactory = new StringBufferPooledObjectFactory(); PooledObjectFactory<StringBuffer> threadSafePooledObjectFactory = PoolUtils.synchronizedPooledFactory(stringBufferPooledObjectFactory);…… Continue reading PoolUtils synchronizedPooledFactory
Custom Qualifier with @Bean annotation
Custom Qualifier with @Bean annotation In this post under Spring Core, I will show with example how to create a custom qualifier and use it with “@Bean” annotation. For our example, I will create a “@DaoGenre” custom qualifier as shown below Custom Qualifer package core.package46; import org.springframework.beans.factory.annotation.Qualifier; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;…… Continue reading Custom Qualifier with @Bean annotation
PoolUtils synchronizedPool
In this post under Apache Pool, I will show with example how to create a synchronized object pool. Below is the complete main class for your reference Main class package package16; import org.apache.commons.pool2.ObjectPool; import org.apache.commons.pool2.PoolUtils; import org.apache.commons.pool2.impl.GenericObjectPool; public class StringBufferPoolExample16 { public static void main(String[] args) { GenericObjectPool<StringBuffer> genericObjectPool = new GenericObjectPool<StringBuffer>(new StringBufferPooledObjectFactory()); ObjectPool<StringBuffer> threadSafeGenericObjectPool…… Continue reading PoolUtils synchronizedPool
Custom Qualifier with @Component annotation
In this post under Spring Core, I will show with example how to create a custom qualifier and use it with “@Component” annotation. For our example, I will create a “@MovieGenre” custom qualifier as shown below Custom Qualifier package core.package45; import org.springframework.beans.factory.annotation.Qualifier; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Qualifier @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME)…… Continue reading Custom Qualifier with @Component annotation