In all my previous post under DotEnv, I showed how to load environment properties from a file named “.env”. The “.env” file can be present in the project directory or in some other directory. By default, DotEnv is configured to search under project directory. In one of my previous posts, I showed how to change…… Continue reading Loading environment properties from custom .env file
Wiring together @Bean annotated beans using constructor approach
In this post under Spring Core, I will explain with example how to wire two beans annotabed with @Bean annotation using constructor. For our example lets take the below two bean classes. Bean1 package package10; public class Bean1 { private Bean2 bean2; public Bean1(Bean2 bean2) { System.out.println(“Hello its Bean1”); this.bean2 = bean2; } } As…… Continue reading Wiring together @Bean annotated beans using constructor approach
Using @DependsOn with @Component annotation
In this post under Spring Core, I will show with example how to use “@DependsOn” annotation to indicate dependencies between two beans marked with “@Component” annotation. For our example we have two beans “Bean1” and “Bean2” and both are annotated with “@Component” annotation. Now to declare that “Bean2” is dependent on “Bean1”, we annotate the…… Continue reading Using @DependsOn with @Component annotation
Giving custom name to @Component annotated beans
In this post under Spring Core, I will show with example how to give custom names to classes annotated with “@Component” annotation. By default when we annotate a class with “@Component” annotation, the name of the bean will be created from the class name, where the first letter of the class name will be lowercase.…… Continue reading Giving custom name to @Component annotated beans
Loading .env file from a specific folder
In previous post under DotEnv, I showed that by default DotEnv checks for “.env” file in the project directory when static “load” method is called. So if your project directory is in “D:\ProgrammingConcepts\JavaSEConcepts\DotEnvConcepts” the “.env” file should be present directly under the “DotEnvConcepts” folder. If present in subfolders under “DotEnvConcepts” it will not load that…… Continue reading Loading .env file from a specific folder
Spring @Component and @ComponentScan annotation example
In this post under Spring Core, I will show with example the purpose and how to use “@Component” and “@ComponentScan” annotation together. Till now in all my previous post, I have been defining a bean using “@Bean” annotation in an “@Configuration” annotated class as shown below package package1; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import…… Continue reading Spring @Component and @ComponentScan annotation example
Accessing an environment variable
In this post under DotEnv, I will show with example how to access a particular environment variable. For example I have created “.env” file with below data. Env File MY_ENV_VAR1=some_value1 MY_ENV_VAR2=some_value2 Now to retrieve the value of environment variable “MY_ENV_VAR1” we call the non static “get” method of “DotEnv” class as shown below Main class…… Continue reading Accessing an environment variable
Loading .env files
In this post under DotEnv, I will show with example how to load a .env file. Below is the complete main class Main class 1 package defaultPackage; 2 3 import io.github.cdimascio.dotenv.Dotenv; 4 import io.github.cdimascio.dotenv.DotenvEntry; 5 6 public class Example1 { 7 public static void main(String[] args) { 8 Dotenv dotenv = Dotenv.load(); 9 for(DotenvEntry entry…… Continue reading Loading .env files
Using @DependsOn annotation
In this post under Spring Core, I will explain with example the purpose and how to use the “@DependsOn” annotation. In an Object Oriented Programming, no object is an island, it depends on other objects to perform their job. When Spring loads the application context, it creates the beans in following order. If a bean…… Continue reading Using @DependsOn annotation
Using @Data annotation example
In this post under Lombok, I will explain with example the purpose and how to use “@Data” annotation. In all my previous posts under Lombok,1) if I need to add getter, setter I would add “@Getter” and “@Setter” annotation2) if I need to add toString method, I would add “@ToString” annotation3) if I need to…… Continue reading Using @Data annotation example