It looks like you expected the BeanD object that you created in line 29 would be injected in the TestSpringServiceImpl bean. But that's not how autowiring works.
First of all, Spring doesn't know anything about the BeanD object that you created in line 29 with "new", so it can't inject this object anywhere. It's going to create a new instance of BeanD itself, using the no-args constructor, and that's what's going to be injected. The point with Spring beans is, that
you should let Spring create the beans, and not create them yourself at arbitrary points in your code - Spring is not automatically going to know about any object that you create wherever in your code.
To make it work, you can do this:
1. Remove the @Component annotation from class BeanD, so that Spring isn't automatically going to create a singleton instance of BeanD.
2. Add @Configuration to class TestSpringAutowire, and add a @Bean method to it, which is the factory method to create the BeanD instance that Spring is going to use:
The @Configuration annotation tells Spring that it should look for factory methods in that class to create beans. You should annotate those factory methods with @Bean.