CurssedHammer
CurssedHammer

Reputation: 119

Springboot application packaged as a library to be used in another springboot application

The scenario I have is as follows:

  1. I have a libraryFile say "LIB" which has some business logic
  2. I have a springboot application(APP1) that uses this LIB as a dependency
  3. I have another springboot application(APP2) which needs to use code from both APP1 and LIB so I refer to LIB and a jar created from classes in APP1

When I Launch the APP2, It launches fine. But when I test using an http request I get a NoClassDefFoundError for some classes in LIB.

Is there an approach that would be a good implementation for this scenario.

Code flow: Controller(APP2)->Service(APP@)->Service(APP1)->Business logic classes(LIB)

Upvotes: 2

Views: 699

Answers (1)

Navneet agarwal
Navneet agarwal

Reputation: 209

A better design :-

  1. Pull out the common code you have in APP1 and place it in a new LIB, or the same LIB you already have.
  2. Add the new/old LIB as a dependency of Both Apps, and consume the common code from there.

-OR-

Run both the services independently and add a http call between the 2 services.

Usually when you want to have libs in a micro service architecture, they are supposed to be plain Java Classes so that they can be consumed anywhere.

One reason the current setup might not be working is the services in APP1 might not be getting the required dependencies injected as it is supposed to.

Upvotes: 1

Related Questions