• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring Jar giving null pointer exception

 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created a Jar using Spring and maven. I had dependencies injected and auto-wiring happening when I tested it using a main method in the same jar.

But I wanted to cross check if this jar can be used in a non-spring environment later. When I am using this jar's classes without any spring configuration. I tend to get null pointer exceptions for the places where dependencies/auto-wiring is expected to happen but it is not..... this is because though the jar is bundled it is not initialized in a spring-way.

Is it the case that jars created via spring are bound to be used in a spring-based environment later so that spring XML and auto-wiring/injection happen right for the created jar? ??
 
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
Well.. yeah!! Spring Core framework is injecting the dependencies for you. If you instantiate a bean outside of Spring, then you have to do the dependency inject yourself

So, for example:-



The following code will work fine



The following code will give Null pointer exception



If you want to use B without Spring's DI, you will have to do the DI yourself



 
Akhilesh Trivedi
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is a pity then... if you got one of you component on Spring, you better want to get all of them on that side.!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic