美文网首页
Maven 多模块 + SSM框架

Maven 多模块 + SSM框架

作者: shpunishment | 来源:发表于2018-09-14 15:46 被阅读0次

    TestMultiModuleTest 为父项目,其余为子模块
    test-api 存放bean和service的接口,普通的maven模块,没有选择archetype
    test-provider 存放dao和service接口的实现,spring和mybatis的配置文件,普通的maven模块,没有选择archetype。依赖于test-api模块,需要在该模块的pom.xml中添加
    test-web 存放controller和springMVC的配置文件,选择archetype为maven-archetype-webapp。依赖于test-api,test-provider模块,需要在该模块的pom.xml中添加

    项目 TestMultiModuleTest pom.xml

    <?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>
    
        <groupId>com.shpun</groupId>
        <artifactId>TestMultiModuleTest</artifactId>
        <packaging>pom</packaging>
        <version>1.0-SNAPSHOT</version>
        <modules>
            <module>test-web</module>
            <module>test-provider</module>
            <module>test-api</module>
        </modules>
    
        <dependencyManagement>
            <!-- 依赖管理,子模块根据需要从父项目的获取 -->
        </dependencyManagement>
    
    </project>
    

    模块 test-api pom.xml 不变
    模块 test-provider pom.xml

    <?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">
        <parent>
            <artifactId>TestMultiModuleTest</artifactId>
            <groupId>com.shpun</groupId>
            <version>1.0-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
    
        <artifactId>test-provider</artifactId>
    
        <dependencies>
            <!-- 模块test-api依赖 -->
            <dependency>
                <groupId>com.shpun</groupId>
                <artifactId>test-api</artifactId>
                <version>${project.parent.version}</version>
            </dependency>
    
            <!-- 无需添加<version></version>标签 -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <scope>test</scope>
            </dependency
    
        </dependencies>
    
    </project>
    

    模块 test-web pom.xml

    <?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">
        
        <parent>
            <artifactId>TestMultiModuleTest</artifactId>
            <groupId>com.shpun</groupId>
            <version>1.0-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
    
        <artifactId>test-web</artifactId>
        <packaging>war</packaging>
    
        <name>test-web Maven Webapp</name>
        <!-- FIXME change it to the project's website -->
        <url>http://www.example.com</url>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.7</maven.compiler.source>
            <maven.compiler.target>1.7</maven.compiler.target>
        </properties>
    
        <dependencies>
    
           <!-- 模块test-api依赖 -->
            <dependency>
                <groupId>com.shpun</groupId>
                <artifactId>test-api</artifactId>
                <version>${project.parent.version}</version>
            </dependency>
           <!-- 模块test-provider依赖 -->
            <dependency>
                <groupId>com.shpun</groupId>
                <artifactId>test-provider</artifactId>
                <version>${project.parent.version}</version>
            </dependency>
    
        </dependencies>
    
        <build>
            <finalName>test-web</finalName>
            <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
                <plugins>
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <version>3.0.0</version>
                    </plugin>
                    <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>3.0.2</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.7.0</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.20.1</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>3.2.0</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-install-plugin</artifactId>
                        <version>2.5.2</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-deploy-plugin</artifactId>
                        <version>2.8.2</version>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </project>
    

    项目结构

    项目列表


    项目列表.PNG

    模块test-api


    模块test-api.PNG
    模块test-provider
    模块test-provider.PNG

    模块test-web


    模块test-web.PNG

    总结

    一开始test-provider和test-web两个模块都是webapp,两个模块的spring配置文件分开读取。test-provider读取spring,mybatis配置文件;test-web读取springMVC配置文件。但在test-provider中的spring的配置文件一直读取不到,classpath:和classpath*:都不行。部署的有两个webapp,分两个tomcat部署也不行,合并部署也不行。留个坑。

    分开读取配置文件待解决

    改成在test-web中的web.xml读取所有的配置文件classpath:application-.xml。

    相关文章

      网友评论

          本文标题:Maven 多模块 + SSM框架

          本文链接:https://www.haomeiwen.com/subject/gkeugftx.html