@Named and @Component annotations are used for the same purpose. Both the annotations are used for enabling a class to be auto detected as the bean definition for spring’s application context. The following are the main different of these two annotations. @Named is part of the. Java specification. It is more recommended since this annotation …
Spring IOC
Bean Definition Inheritance in Spring
In my previous post I have explained how to inherit collection values from the parent bean. Spring offers out of the box support on inheritance for the bean definitions in the XML configuration file. You can define any number of beans and extend them by using the parent attribute in the bean element. Child bean can …
How to Merge Collections in Spring?
In my previous post I have explained about how to use collections in Spring. This tutorial explains how to merge collections or inherit the values from the parent bean. In some scenarios we need to define a bean as abstract using the abstract=true in the bean definition. It means that another bean definition will be …
Circular Dependency in Spring
This tutorial explains one of the basic mistake done by the spring developers while defining the spring beans. Spring will not allow Circular Dependency and will throw an exception (BeanCurrentlyInCreationException) at the time of loading the configuration files. Also it is not good practice to design your project to have the circular dependency. What is …
How to use Initialization callback methods while creating Spring bean?
Initialization callback methods Springframework provides flexibility to initialize its Beans using the user defined methods. There is some scenario where application developer want to initialize the beans properties after setting all the values. The following example program demonstrates by defining a custom method to initialize the calues. Spring’s managed bean has to implement InitializingBean from …
Simple example for Before advice and After Advice in Spring Framework
BeforeAdvice and AfterReturningAdvice This tips presents a very simple program for invoking the Before Advice and After Returning Advice in the Spring Framework. Thsese two methods are part of Spring’s AOP implementation and used as interceptor methods. the following program create spring beans using the standalone java program and invokes the business logic method. Business …
How to read xml file and inject bean reference using Spring Framework?
Introduction This article presents sample source code for creating the Bean instance using the Spring Framework. This is basic example to read configuration file from the file system and create the beans from the applicationContext.xml file. This xml file define two beans Employee and Address. Address bean is injected inside Employee bean using the ref …