In the above class if I've autowired annotation on the "filed" without SET method, the autowiring is not working.
But I've read the documentation, setting @Autowired on the filed shoudl work fine.
Can you please tell me if there is anything being done incorrectly?
You shouldn;t create an instance of TestSpringAutowireyourself. Spring can only autowire into beans that it has created itself. When you load your application context, spring will create an instance of TestSpringAutowire. That spring created instance will be wired correctly. You should get that instance from Spring instead of creating your own instance
So, change line 20 to
BTW, your code is seriously messed up. Generally you don;t put setter methods around static members. You might want to look at Spring's code samples, or get a good book
posted 5 years ago
Thank for the explanation. I've changed the erroneous line as mentioned and autowiring works good.
I'm new to spring, appreciate if you could post the code sample and documentation urls.
Thanks in advance.
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?