0

I've a jar which contains java classes (Could have multiple classes). In my spring boot application, I've to add this jar in classpath at runtime and need to register classes as bean in ApplicationContext.

I also have to make sure that loading jar and bean registration happens in certain order so that bean wiring happens correctly. Can some one please help.

Best Regards,

Maneesh Saxena

Maneesh
  • 131
  • 2
  • 6
  • This post seems to do what you want. https://www.programmerall.com/article/97882278492/ – btafarelo Jun 13 '22 at 09:02
  • Even I tried this one. But below line of code doesn't even compile well. Class> clazz = classLoader.loadClass(pluginClass); – Maneesh Jun 14 '22 at 07:27

1 Answers1

0

For example, if you have a class Foo on your external jar which looks like:

public class Foo {
   public Foo(String arg1, String arg2){
   // your constructor
   }
}

On your spring-boot application, you can register it as bean using @Bean:

@Configuration
public class AppConfig{ 
   @Bean
   public Foo fooBean(){
   return new Foo("toto","bar");
  }
}
Katy
  • 1,023
  • 7
  • 19