java - 我能否以某种方式运行多个与一个 SpringBootApplication 共享同一库模块的 Web 模块?

标签 java spring maven spring-boot

我正在启动一个 Spring 项目,该项目应由四个主要模块组成:

  1. 核心模块 - 具有服务和存储库层(应代表其他模块的公共(public)库)
  2. 管理模块 - 应包含自己的安全配置和端点( Controller )
  3. 客户模块 - 应包含另一个安全配置和 Controller
  4. ?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)

最佳答案

当然,这是可能的。您只需要注意以下几点:

  1. 您的网络模块应包含所有其他模块作为依赖项;
  2. 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/

相关文章:

java - SecureRandom 的创建很慢,即使在 Java 8 中也是如此

java - Spring中具有多种角色的组件

apache - Maven 依赖项排除 : Same artifact-id issue

maven - 将 mvn site-deploy 与 github 页面结合使用的多模块示例

java - 如何创建可重用的测试代码而不创建循环依赖项?

JavaFX FXMLLoader 无法找到文件

java - 关于 AbstractApplicationContext.getBeansOfType() 和 getBean() 的问题

java - Spring:如何从一个对象中提取数据并将其插入到另一个对象中

java - AutoCompleteTextView 强制显示所有项目

java - 在java中创建 Parquet 文件