我正在启动一个 Spring 项目,该项目应由四个主要模块组成:
- 核心模块 - 具有服务和存储库层(应代表其他模块的公共(public)库)
- 管理模块 - 应包含自己的安全配置和端点( Controller )
- 客户模块 - 应包含另一个安全配置和 Controller
- ?Web 模块 - 包含应启动管理和客户模块的 SpringBootApplication。
这可能吗?或者我应该将项目分成两个具有公共(public)库的 Spring Boot 项目? 我可以配置一个构建,其中将管理和客户模块构建为 .war 文件并在 Web 模块中使用 SpringBootApplication 运行它吗?
客户和管理模块不必位于同一端口。唯一重要的是同时运行它。
以下是我当前项目的结构。
/project-root
-pom.xml (pom packaging defined; modules: core, web-admin, web-customer)
/core
-src (contains service and repository classes)
-pom.xml (jar packaging)
/web-admin
-src (contains controllers and security configuration for admin portal)
-pom.xml (jar packaging for now; dependency on core)
/web-customer
-src (contains controllers and security configuration for customers)
-pom.xml (jar for now; dependency on core)
/web
-src (should contain SpringBootApplication to run all the modules)
最佳答案
当然,这是可能的。您只需要注意以下几点:
- 您的网络模块应包含所有其他模块作为依赖项;
- SpringBootApplication 类应该位于顶级包,否则您将不得不使用
baseScanPackages
属性;
例如:
/core
com.example.app.core <--- All the core classes would be on this package
/web-admin
com.example.app.admin <--- All the admin classes would be on this package
/web-customer
com.example.app.customer <--- All the customer classes would be on this package
/web
com.example.app <--- The SpringBootApplication class should be at this level
Can I maybe configure a build in which Admin and Customer modules are built as .war files and run it with SpringBootApplication in Web module?
您不需要将 admin 和 customer 模块打包为 war
文件,jar
打包就完美了。
Customer and Admin modules don't have to be on the same port.
这是一个硬性要求吗?如果是,那么您最好编写两个不同的应用程序。否则,所有 API 都可以在同一端口上访问。
关于java - 我能否以某种方式运行多个与一个 SpringBootApplication 共享同一库模块的 Web 模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55862810/