Spring Boot项目设置设计决策
我们将使用Spring Boot创建服务.我们最初的想法是,每个服务(不一定是微服务)都是独立的,并作为.jar文件进行部署. Maven进行构建.
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.
我想知道什么是好的Spring Boot项目结构,因为每个服务都是独立的,但是我猜服务仍然会有一些可以在或应该在服务之间重用的代码/实体
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
选项:
-
每个服务都是一个独立的Spring Boot项目.仅实现实际服务所需的实体,控制器和工具.
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?
所有服务都在同一代码库中创建.所有服务都可以重复使用所有其他服务中的实用程序,控制器等 良好:易于重用 不好:JVM现在可以处理所有服务调用了吗?服务边界现在由负载均衡器处理吗?
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?
感谢您的帮助!
将通用逻辑放入单独的瘦JAR中,将其放在工件库和版本中,与服务分开.这种公共库可以作为独立项目生存(类似于您在项目中使用的其他JAR依赖项).
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).
每个服务都将使用此JAR/s作为常规依赖项.
Each service will use this JAR/s as normal dependency.
我在团队中工作,我们将这种方法用于以下方面:
I was working in team, where we used this approach for:
- 验证码
- 用于记录的AOP
- 一些常见的验证码
- 一些常见的领域对象
- 异常处理