• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Automatic Wiring

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am very new to Spring, reading Spring in Action 4th edition. I downloaded 4.2.2 release API, and wrote some code. When I run main method of GeometryTest, it gives NullPointerException. Why automatic wiring is not working? What am I missing? Please help.

-------------------------------------------------------------------------------


-------------------------------------------------------------------------------

-------------------------------------------------------------------------------

-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your Test class should be run from a Spring Unit Test runner.

You can't just do new GeometryTest() and expect Spring to auto-magically inject beans into a class that you instantiated. For Sprint to do it's Autowiring, Spring has to instantiate the bean. If you are instantitating a bean yourself, Spring isn't in the picture at all. For test classes, you do this by putting a @RunWith(SpringJUnit4ClassRunner.class) and adding test methods into your test class. You will be run your test through JUnit

 
reply
    Bookmark Topic Watch Topic
  • New Topic