Spring does not have the ability to automatically install dependencies in beans so that it does not create itself. Dependency injection must be handled by the Spring container. If you use new to create objects, you are not using the Spring container at all. Instead of creating an instance, you should request a container for the objects. Thus, the container will be bound to the life cycle of this object.
A a = new A();
So your object referenced by a is not managed by Spring. Therefore, it will not be able to insert any dependent objects into a .
You should get an instance of a from the container, something like this:
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); A a = context.getBean("myBean");
PS: - Although out of context, but this to-new-or-not-to-new blog is a pleasant read.
source share