Spring boot 多模塊開發(fā)遇到的坑

1.引言

最近準(zhǔn)備做一個(gè)開源項(xiàng)目。沒得人寫app接口,無奈我只有零時(shí)充當(dāng)后臺(tái)人員 了。因?yàn)橐郧坝眠^Spring boot,感覺這個(gè)框架很不錯(cuò),快速搭建起項(xiàng)目。于是選用它作為后臺(tái)開發(fā)框架。下面就把自己這幾天遇到的大大小小的坑說下。百度了很多都沒找到。

2.正題

項(xiàng)目的結(jié)構(gòu):

Paste_Image.png

rent:是一個(gè)project,創(chuàng)建的方式。

Paste_Image.png
rentModel,rentApp,rentCms 都是rent下面的 module依賴。其中rentApp,rentCms 都依賴rentModel。

rentApp的 pom.xml

<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/maven-v4_0_0.xsd">
    <parent>
        <artifactId>rent</artifactId>
        <groupId>com.xinyi</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>rentApp</artifactId>
    <packaging>jar</packaging>
    <name>rentApp Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>com.xinyi</groupId>
            <artifactId>rentModel</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.2.2</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>springloaded</artifactId>
                        <version>1.2.5.RELEASE</version>
                    </dependency>
                </dependencies>
                <!--<executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>-->
            </plugin>
        </plugins>
    </build>
</project>

pom.xml 已經(jīng)添加了rentModel 依賴了。。

問題1.

通過maven spring-boot:start運(yùn)行rentApp的時(shí)候 老提示,找不到rentModel 模塊。奇怪的是以Application啟動(dòng),能運(yùn)行。。

解決:

先clean,rentApp,在build rentApp。。這樣的問題一般都是maven構(gòu)建的問題。不斷的去clean,rebuild。

問題2.

項(xiàng)目打包的時(shí)候,在服務(wù)器上運(yùn)行,有提示找不到rentModule 里面的類,找不到里面的方法。。

解決:

先clean rentModel,然后編譯rentModel。然后打包rentModel,然后上傳到本地倉庫。最后在打包rentApp 就ok了。

以上的打包,編譯全部都是 通過maven 實(shí)現(xiàn)的

Paste_Image.png

以上就是我在搭建多模塊的spring boot項(xiàng)目 遇到的問題。。折騰了 百度了很多都沒找到靠譜的方案。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容