since bean creation phases are as below:
- Instantiation
- Populating Properties(Spring scans the beans that implement Aware interfaces and starts setting relevant properties)
- Pre-Initialization (Spring’s BeanPostProcessors get into action in this phase)
- AfterPropertiesSet
- Custom Initialization
- 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.