why @Autowired has higher precedence than Aware callback methods in spring bean lifecycle?

Viewed 22

since bean creation phases are as below:

  1. Instantiation
  2. Populating Properties(Spring scans the beans that implement Aware interfaces and starts setting relevant properties)
  3. Pre-Initialization (Spring’s BeanPostProcessors get into action in this phase)
  4. AfterPropertiesSet
  5. Custom Initialization
  6. Post-Initialization

and annotations like @Autowired, @Value and ... are handled by AutowiredAnnotationBeanPostProcessor that this class is a BeanPostProcessor and Aware class , so if I have a class that implements a aware like BeanNameAware , why @Autowired annotation has higher precedence than Aware callback methods?

@Component
public class Test1 implements BeanNameAware {
    private Test test;

    @Autowired
    public void setTest(Test test) {
        System.out.println("setter");
        this.test = test;
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("aware:" + name);
    }
}

In above example setter print sooner than aware:name , I want to know why is this happening whereas both of them are from second phase of bean creation phases.

0 Answers
Related