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
Tag: Spring Framework
Registering init and destroy methods using @Bean annotation
In this post under Spring Core, I will explain with example how to register initialization and destroy methods for a bean. FYI, a bean initialization method is called when the bean is created and destroy method is called before bean is garbage collected. All we need to tell Spring is which are the initialization and…… Continue reading Registering init and destroy methods using @Bean annotation
Giving custom name to @Bean annotated beans
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
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
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
Setter injection example with more than one argument (@Autowired)
In this post under Spring core, I explains how to instruct Spring framework to call a setter method (which take more than one argument) while creating a bean. In most of the cases, the setter methods of a class takes only one argument but if a case arises where a setter method has to take…… Continue reading Setter injection example with more than one argument (@Autowired)