Spring Boot project setup design decisions

我与影子孤独终老i 提交于 2019-12-30 10:38:13

问题


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!


回答1:


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


来源:https://stackoverflow.com/questions/35223505/spring-boot-project-setup-design-decisions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!