You cannot do it like that. As Sotirios said, Spring must create an instance to inject it into ClassA . You can probably do this manually using the application context. Sort of:
public class ClassA { @Inject private ApplicationContext appContext; private ClassB classB;
And then use getter to access the object.
source share