带有Spring Boot的多模块Web应用程序Maven架构



我正在构建一个包含多个模块的Web应用程序,我想将这些模块中的每个模块分为一个项目。这是我第一次试图做这样的事情,我曾经在一个项目中将应用程序制作,我不想用错误的体系结构开始开发。我想做的:

--Maven parent project
    -- main app: Spring boot, Database connection, authentication, user management.
    -- Module 1,2 .. n: modules, repositories, controllers

因此,这个想法是通过功能在用例透视图上分裂项目的。问题是:该体系结构可以毫无问题地工作,如何使用Maven进行配置?

您需要这样的东西:

1)有一个将所有这些都固定在一起的父pom,这是您的父母,有弹簧靴的父母:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
    </parent>
    <groupId>com.essexboy</groupId>
    <artifactId>boot-parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>boot-library</module>
        <module>boot-web</module>
    </modules>
</project>

2)具有您希望的尽可能多的库模块:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>boot-parent</artifactId>
    <groupId>com.essexboy</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <artifactId>boot-library</artifactId>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

3)然后拥有尽可能多的春季启动模块,这些模块将吸引同一项目所需的库:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>boot-parent</artifactId>
        <groupId>com.essexboy</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>boot-web</artifactId>
    <dependencies>
        <dependency>
            <groupId>com.essexboy</groupId>
            <artifactId>boot-library</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- tag::actuator[] -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!-- end::actuator[] -->
        <!-- tag::tests[] -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- end::tests[] -->
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

最新更新