Spring Boot(和 Web)多模块项目

发布于 2025-01-17 03:56:45 字数 1049 浏览 1 评论 0原文

我正在尝试创建一个多模块 Spring Boot 项目(Struts2/Ibatis 项目的重写),我希望将其布局如下:

-- Parent project.  //contains <properties> that should be shared through the child modules
 |- model //Contains ONLY Hibernate entities
 |- dataaccess //uses 'model' but has dataManagers and dataRepositories with Spring @Autowired beans
 |- webapp //uses 'dataaccess' module and uses Spring @Controller for processing requests
 |- scheduled //Spring boot console app that runs once a day, uses 'dataaccess' module for DB read writes

我如何设置每个 pom 以便:

1 - <properties> only need to be set in one pom but are accessible to the other modules
2 - Where should I use <parent> <artifactId>spring-boot-starter-parent or should I somehow access the spring boot modules in some other way?
3 - How can I optimise the pom heirarchy so that only the necessary libraries are exposed to the relevant module (i.e. in the 'model' module there will be no need to have access to spring-boot-starter-web etc.)

谢谢。

I'm attempting to create a multi-module spring boot project (a rewrite of a Struts2/Ibatis project) that I wish to lay out as follows:

-- Parent project.  //contains <properties> that should be shared through the child modules
 |- model //Contains ONLY Hibernate entities
 |- dataaccess //uses 'model' but has dataManagers and dataRepositories with Spring @Autowired beans
 |- webapp //uses 'dataaccess' module and uses Spring @Controller for processing requests
 |- scheduled //Spring boot console app that runs once a day, uses 'dataaccess' module for DB read writes

How can I set up each pom so that:

1 - <properties> only need to be set in one pom but are accessible to the other modules
2 - Where should I use <parent> <artifactId>spring-boot-starter-parent or should I somehow access the spring boot modules in some other way?
3 - How can I optimise the pom heirarchy so that only the necessary libraries are exposed to the relevant module (i.e. in the 'model' module there will be no need to have access to spring-boot-starter-web etc.)

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逐鹿 2025-01-24 03:56:46

在这种情况下,您可以有 5 个 pom.xml 文件。每个模块(包括父模块)都有自己的 pom.xml。

  1. 父pom文件可以拥有可以在子模块中共享的所有属性
  2. 如果您有多个使用spring-boot-starter-parent依赖项的模块,那么将其放在父pom中是有意义的,否则您可以它在需要的模块中。
  3. 是否可以在每个 pom 中模块化特定的依赖项以进行优化。

我们对于 spring-boot 应用程序有类似的项目结构。我们在父 pom 中有 spring-boot-starter-parent ,在需要的各个模块中有其他库,例如数据访问等。

You can have 5 pom.xml files in this case. Each module (including parent) will have its own pom.xml.

  1. Parent pom file can have all the properties that can be shared in the child modules
  2. If you have more than one module that uses the the spring-boot-starter-parent dependency then it make senses to have it in the parent pom else you can have it in the module where its needed.
  3. If can you module specific dependencies in each pom for optimization.

We have similar project structure for spring-boot application. We have the spring-boot-starter-parent in the parent pom and other libraries like data access etc. in individual modules where its needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文