In this post under Spring Core, I will show with example how to give custom id to beans. Whenever we define a bean with @Bean annotated method, we do it as below @Bean public Bean1 bean1() { return new Bean1(); } The bean id by default will be same as method name. So in the…… Continue reading Giving custom name to @Bean annotated beans
Uncompressing a gzip file
In this post under Java, I will show with example how to uncompress a gzip format file. For decompressing a gzip file, we will use java provided “GZIPInputStream” class. Below is the main code for your reference Main class 1 package zip; 2 3 import java.io.File; 4 import java.io.FileInputStream; 5 import java.io.FileOutputStream; 6 import java.io.IOException;…… Continue reading Uncompressing a gzip file
Compressing a file in gzip format
In this post under Java, I will show with example how to compress a single file in gzip format. For compressing a file in gzip format, we will use java provided “GZIPOutputStream” class. Below is the main code for your reference Main Class 1 package zip; 2 3 import java.io.File; 4 import java.io.FileInputStream; 5 import…… Continue reading Compressing a file in gzip format
Importing multiple @Configuration classes into one master @Configuration class
In this post under Spring Core, I will explain with example how to import multiple “@Configuration” classes into one master “@Configuration” class. In my previous posts, I have created “@Configuration” annotated classes and defined one or two beans in them for my example. Whereas in production code, there will be many bean definitions more than…… Continue reading Importing multiple @Configuration classes into one master @Configuration class
Using @EqualsAndHashCode annotation
In this post under Lombok, I will explain with example the purpose and how to use “EqualsAndHashCode” annotation. This annotation is applied at the class level only. This annotation instructs Lombok to automatically generate “equals” and “hashCode” method. When generating “equals” and “hashCode” method it considers all non-static and non-transient fields. For our example we…… Continue reading Using @EqualsAndHashCode annotation
Setting Environment Variable
In this post under TestContainer, I will explain with example how to set environment variable before starting a container. For our example, we will use the latest “postgres” image from Docker Hub. According to “postgres” help page on Docker Hub we only need to set the environment variable “POSTGRES_PASSWORD” to start the postgres container and…… Continue reading Setting Environment Variable
Registering multiple @Configuration annotated Classes
In the previous post under Spring Core, I explained with example the purpose of “@Configuration” annotation. Just for recap, classes marked with “@Configuration” annotation are informing the Spring framework that it contains bean definitions. Let’s call class marked with “@Configuration” as “Configuration Class”. It will help you in understanding this post. Spring then uses “AnnotationConfigApplicationContext”…… Continue reading Registering multiple @Configuration annotated Classes
Spring @Bean and @Configuration Simple Example
In this post under Spring Core, I will explain with example the purpose of “@Bean” and “@Configuration” annotation. Earlier before the introduction of annotations in Spring project, we used to define beans in xml file. For example if we had a classes as shown below package package1; public class Bean1 { @Override public String toString()…… Continue reading Spring @Bean and @Configuration Simple Example
Changing display name when printing string format of an object
In this post under Lombok, I will show with example, the purpose of “name” attribute in “ToString.Include” annotation. Whenever we use “ToString” annotation on a class, it generates the string format of an object where field name (also can be called as display name) are equal to object property name. So for example if below…… Continue reading Changing display name when printing string format of an object
Configuring the order of filters
In previous post under JAX-RS Client, I showed with example how to register filters for a particular client. The filters are executed in the order they are registered. We can change the order of execution by giving a priority to each filter. Filters with lower priority will be executed first. To demo this, we will…… Continue reading Configuring the order of filters