Short answer : Bean injection happens after creation of instances of your class.

Since in the creation of myTestB (which should start with an uppercase, by the way), you call getVarB on someInstanceA which is not yet injected, you get a NullPointerException.

The second case works because @BeforeClass run one time before first test run, after object creation. Thus when calling someInstanceA#getVarB in getVarB method, someInstanceA is already autowired and not null.