简体   繁体   中英

sharing Java classes between services

I am currently trying to break my Spring monolith app into multiple services. I have many entities (@Entity, POJO) that would be used in different services. Obviously I don't want to copy & paste the common code but it seems very fragile to build a jar file and sharing them between projects.

Here is what I have:

core
  -- @Entity classes
  -- POJO

App1 - deployed independently
  -- src
  -- core classes

App2 - deployed independently
  -- src
  -- core classes

I am using gradle as my build tool, and it looks like it supports multi-project builds. But I am not sure if that means my core becomes its own repo that must be downloaded to be included, or if that is built as a jar and included.

Can anyone point me to a good example or tutorial on this? So far I haven't found a clean way to do this.

You should share that JAR just as you would any other 3rd party JAR.

Move it into a separate project that results in a JAR being published to your Maven repository; modify all services that need it to add that JAR as a dependency.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM