Talking more about AutowiredAnnotationBeanPostProcessor

In the previous tutorial on the bean autowiring using the @Autowired annotation, I mentioned that the AutowiredAnnotationBeanPostProcessor object is used to dynamically place objects that depend on the dependent object. Perhaps some of you are wondering how this object can do that, right? Me too, and that’s why I’ve been through the code of the AutowiredAnnotationBeanPostProcessor class to see what this object actually did.

OK, first I read its constructor, the content is as follows:

Here, you see, this class has a variable called autowiredAnnotationTypes that contains information about three classes, Autowired.class, Value.class, and Inject.class. It is a variable type Set:

This variable is used in 3 different ways to handle 3 annotations: @Autowired, @Value and @Inject.

Take a look at these three methods:

This method is for @Autowired annotation.

This method is for @Value annotation. The use of this annotation, I will say in another tutorial.

This method is for @Inject annotation. The use of this annotation, I will also be covered in another tutorial.

The common point of these three methods is that it calls to another method called findAutowiringMetadata(). And in this method, there is the buildAutowiringMetadata() method, reading the buildAutowiringMetadata() method, you will visualize what the AutowiredAnnotationBeanPostProcessor object does to handle the cases in which you declare @Autowired annotation in the variable, in the method, and in the constructor. Same for @Value annotation and @Inject annotation.

Look at the two methods, I just said.

And

I think you can read this code, right?

Add Comment