• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Spring Autowiring

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've spring beans config with just


and TestSpringServiceImpl is as follows

and the test class with main as below:


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?

Thanks
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Sanju Manc
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic