• 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

Loading jar file at runtime from an external folder in spring boot

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a spring boot application . I want to load external jars from an external folder at runtime in the spring boot application after the application is started without restarting the context. The external jar contains @Service , @Component annotated classes.

What I have tried till now:

I loaded all the classes from the external jar at runtime . I have used a watcher which triggers the loader whenever there is a jar added to the folder being watched.

Below are the steps:
1) Autowire annotationconfigapplicationcontext bean .
2) Load the classes from the external folder using loader
3) register those classes in annotationconfigapplicationcontext
4) restart the annotationconfigapplicationcontext

Also i tried autowiring the classes programatically but the drawback with that is that there might be a @Service class dependent on another @Component class hence I need to maintain the bean creation order which is hard to handle programatically.

Is there a way i can load the classes from the external jar without restarting the application context.
 
Bartender
Posts: 2266
13
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe, you can try  the refresh() method of AnnotationConfigApplicationContext inherited from AbstractApplicationContext.
 
Umesh Sanwal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried by the refresh way , but the refresh reloads the entire context i.e it destroys already created beans and creates them again which I dont want in my case.
 
reply
    Bookmark Topic Watch Topic
  • New Topic