Auto-wiring in spring can also be achieved through Annotation. Annotation is the simplest way to achieve wiring in Spring as it doesn't involve any extra code in XML file. It can be parsed by the Spring container at the time of reading the bean class. An the strange fact is that annotation auto-wiring doesn't use any of the constructor or setter injection for injection the bean property else it uses its own way to inject the bean property. But bean will be detected using the byType process. Annotation can be used with the bean properties, setter method and constructor.

@Autowired is the annotation can be used with the bean properties, constructor and Setter method.

1. Annotation on properties
2. Annotation on constructor
3. Annotation on Setter
4. Annotation on properties where ( required = false )

Note : By default annotation in Spring is disabled, we have to enable it manually by modifying the XML file.

For Enabling Annotation in Spring 

Why Annotation is by default disable in Spring ?
It is because in Spring all the functionality is not supported by annotation rather it is possible with using XML file.

Related Posts:

  • Spring Framework Architecture Spring framework is a layered architecture where Spring 2.x is divided into 6 modules. So here i am going to explain all 6 modules one by one. Spring Core Module: It provide the fundamental part of spring Framework lik… Read More
  • Spring Implicit Wiring : byType In this type of auto-wiring container detect the bean instance with its data type and checks the data type of the bean instance running in the container with the bean type mentioned in the dependency bean. Some of the task … Read More
  • Benefit of using Spring Framework Provide a good programming practice by decoupling the layers. If you are using spring in your project it decouples the layers and hence it's easy to write the test case for them. So it's easy from maintenance point of view.… Read More
  • Bean Loading Type In Spring Loading the bean which is configured in the Spring-context.xml file, can be done in two ways : 1. Eager loading or Aggressive loading 2. Lazy Loading Eager loading or Aggressive loading  In the case of Aggressive l… Read More
  • Alternatives of Open Session In View(OSIV) Today I am going to tell you other alternative you can do in order to avoid LazyInitializationException: Session has been closed. If you are using SPRING with HIBERNATE that you can take the advantages of IOC and AOP. These … Read More

1 comment:

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

201978

Online Members

Live Traffic