This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Modern JavaScript for the Impatient and have Cay Horstmann on-line!
See this thread for details.
Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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: 1944
13
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Does this tiny ad smell okay to you?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic