user1340582
user1340582

Reputation: 19729

Spring Boot project setup design decisions

We will be using Spring Boot to create services. Our initial idea would be that each service (not necessarily microservice) would be self-contained, and deployed as a .jar file. Maven for build.

I'm wondering what would be a good Spring Boot project structure, as each service would be self-contained, but I'm guessing services will still have some code/entities that can or should be reused between services

Options:

  1. Each service is a standalone Spring Boot project. Implements only the entities, controllers, and utils that the actual service requires.

    Good: each service is fully self-contained

    Bad: what about custom utility classes that need to be re-used between services? What about domain objects that services may need to share?

  2. All services are created in the same codebase. All services can re-use utilities, controllers, etc. from all other services Good: easy re-use Bad: A JVM is now able to serve all service calls? service boundaries are now handled by load balancers?

Thanks for any help!

Upvotes: 3

Views: 578

Answers (1)

luboskrnac
luboskrnac

Reputation: 24591

Place common logic into separate thin JAR, place it in your artifact repository and version separately from services. This common library/ies will live it's life as standalone projects (similar to other JAR dependencies you use in your project).

Each service will use this JAR/s as normal dependency.

I was working in team, where we used this approach for:

  1. Authentication code
  2. AOP for logging
  3. Some common validation code
  4. Some common domain objects
  5. Exception handling

Upvotes: 2

Related Questions