Spring Boot项目设置设计决策 [英] Spring Boot project setup design decisions

查看:84
本文介绍了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

选项:

  1. 每个服务都是一个独立的Spring Boot项目.仅实现实际服务所需的实体,控制器和工具.

  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?

所有服务都在同一代码库中创建.所有服务都可以重复使用所有其他服务中的实用程序,控制器等 良好:易于重用 不好: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:

  1. 验证码
  2. 用于记录的AOP
  3. 一些常见的验证码
  4. 一些常见的领域对象
  5. 异常处理

这篇关于Spring Boot项目设置设计决策的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆