当前位置: 首页 > 知识库问答 >
问题:

Spring boot(和web)多模块项目

何建中
2023-03-14

我正在尝试创建一个多模块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.)

非常感谢。

共有1个答案

邢昊焜
2023-03-14

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

  1. 父pom文件可以具有可在子模块中共享的所有属性

我们有类似的项目结构,在父pom和其他库中,如数据访问等,在需要的单个模块中,我们有Spring-boot-starter-父库。

 类似资料:
  • 我有一个基本的SpringBoot应用程序。使用Spring初始值设定项、嵌入式Tomcat、Thymeleaf模板引擎,并将包作为可执行的JAR文件。是一个带有Spring Boot的多模块项目,该项目将有3个模块。这里是父模块pom。xml 这里是模块核心 这里是模块web: 从父根目录,我使用以下方法生成所有模块: 但问题是tdk-web-0.0.2-SNAPSHOT。jar不包含tdk-c

  • 父项目为demo-mybatis子模块为mybatis-dao、demo-service。demo-mybatis pom.xml如下: 4.0.0 pom mybatis-DAO Demo-service Demo-mybatis-app org.springframework.Boot spring-boot-starter-parent 2.3.2.release com.example D

  • 我有一个带有myapp-core和myapp-web模块的myapp父pom类型maven项目。myapp-core模块作为依赖项添加到MyApp-Web。 myapp-core模块中的所有类都位于根包com.myapp.core中,而myapp-web模块中的所有类都位于根包com.myapp.web中 主要的application.java也在com.myapp.web包中。由于我的核心模块根

  • 我在教程两个模块的帮助下创建了一个springboot mutimodule项目--一个后端(java类),另一个forntend(angular 5应用程序)我在后端模块中包含了前端模块的依赖项。我正在创建一个jar使用maven资源插件。我也在将静态资源复制到pom.xml中构建目录的静态文件夹中。我还有一个@Controller返回“index”。当我运行jar时,我希望看到index.ht

  • 关于maven项目结构,我有两个问题: 1)我正在创建一个maven多模块项目,并且想知道是否可以将模块的所有公共依赖项放在父POM中?这是正确的做法吗? 2)如果我正在创建一个包含所有web.xml和JSP文件的maven webapp项目,那么web控制器、侦听器和模型对象应该驻留在哪里?在一个单独的maven jar项目中还是在同一个webapp项目中?

  • 我正在尝试为一个现有的应用程序编写单元测试用例,该应用程序有多个模块,每个模块中都有主类。有多个类具有\@SpringBootApplication。我写了一个简单的测试用例,它失败了,错误如下。我如何继续我的测试用例中的一个。 java.lang.IllegalStateException:在文件[C:\My Data\Workspace\Services2\MicroServices\Repo