Spring has no chance to autowire dependencies in beans that it does not create itself. The dependency injection should be handled by the Spring container. If you use new
to create objects then you are not using the Spring container at all . Instead of creating the instance yourself , you should request the container for objects. This way the Container will have a hook on the life-cycle of that object.
A a = new A();
This way your object referenced by a
is not managed by Spring . Hence it will not be able to inject any dependent objects into a
.
You should get the instance of A
from the container, somewhat like this :
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("applicationContext.xml");
A a = context.getBean("myBean");
P.S: - Though out of context , but this blog to-new-or-not-to-new is a nice read.