• 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

Injecting beans of a jar from another component/app

 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question is pertaining to this thread.

https://coderanch.com/t/652792/Spring/Spring-Jar-giving-null-pointer


When we create a Spring Jar and it is consumed by another component/app, how do we initialize/inject the depencies of the included jar, do we need to know the name of the spring xml file and include that as well in our new component/app's xml file?
 
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
There are 4 ways you can do this

1) do not include spring xml files in your jar. Your client can have his own spring xml to ok instantiate your classes. You are making your work simple. You are putting work on your clients

2) include a spring xml in your jar that your client can import. From a spring xml, you can import other spring xmls. As long as the imported xml is in classpath, spring can import it. This way you reduce work for your client, but you force them to use spring. Also you lose flexibility.

3) implement a namespace handler.
Using a namespace handler you can have your namespace with custom xml tags. When the client uses your custom tag, your namespace handler is invoked when the xml is parsed. Your namespace handler can programmatically add bean definition to the factory. This option is very complicated for you, but is the most flexible.

4) completely hide the bean factory. You can put your spring xml inside your jar. Also inside your jar put a Singleton class that wraps the bean factory. Your client can call this singleton class to get the beans.
reply
    Bookmark Topic Watch Topic
  • New Topic