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
Mapping beans that refer another bean as its properties
In all my previous posts under MapStruct, whenever I gave an example of MapStruct, I used a bean having only primitive data types and not user defined types. In this post, I will show with example how to do mapping of a bean which refers to another bean as its property. For our example I…… Continue reading Mapping beans that refer another bean as its properties
Autowiring by Name (Using @Qualifier with @Component annotation)
In previous post under Spring Core, I showed with example how to use “@Qualifier” annotation with “@Bean” annotation. In this post under Spring Core, I will show with example how to use “@Qualifier” annotation with “@Component” annotation. For our example I will create an interface named “IMovie” as shown below IMovie package core.package44; public interface…… Continue reading Autowiring by Name (Using @Qualifier with @Component annotation)
Using @Lookup annotation with arguments
In this post under Spring Core, I will explain with example how to use “@Lookup” annotation with arguments. In the previous post under Spring Core, I showed the purpose and how to use “@Lookup” annotation without any arguments. Just for recap,1) “@Lookup” annotation is applied on the method level2) It tells Spring to create a…… Continue reading Using @Lookup annotation with arguments
Using defaultExpressions
In this post under MapStruct, I will explain with example the purpose of “defaultExpressions”. Default expressions are the expressions that are executed with the source attribute is null. I have introduced you to expressions in MapStruct in previous posts. Till now we were using expressions without the source attribute. But in case of default expressions…… Continue reading Using defaultExpressions
Using @Lookup annotation without arguments
In this post under Spring Core, I will explain with example the purpose of “@Lookup” annotation used without any arguments. “@Lookup” annotation is applied only on methods. “@Lookup” annotation can be used with or without arguments. In this post I will show how to use “@Lookup” annotation without arguments. In case of “@Lookup” annotation without…… Continue reading Using @Lookup annotation without arguments
ObjectPool getReturnedCount example
In this post under Apache Pool, I will explain with example the purpose of “getReturnedCount” method. This method is mainly used when generating statistics of a particular object pool. This method returns the total number of objects returned back to pool during the lifetime of the pool. So for example, if we have pool running…… Continue reading ObjectPool getReturnedCount example
Using decorator during mapping
In this post under MapStruct, I will show how to use decorator to implement pre and post mapping operations. For our example, we will use the “Student” and “StudentDTO” pojo classes. The class structure is as shown below Student package package26; public class Student { private int id; private String name; private String className; //Removed…… Continue reading Using decorator during mapping