Spring boot 多模块开发遇到的坑

2017-09-30  本文已影响118人  过期的薯条

1.引言

最近准备做一个开源项目。没得人写app接口,无奈我只有零时充当后台人员 了。因为以前用过Spring boot,感觉这个框架很不错,快速搭建起项目。于是选用它作为后台开发框架。下面就把自己这几天遇到的大大小小的坑说下。百度了很多都没找到。

2.正题

项目的结构:

Paste_Image.png

rent:是一个project,创建的方式。

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 已经添加了rentModel 依赖了。。

问题1.

通过maven spring-boot:start运行rentApp的时候 老提示,找不到rentModel 模块。奇怪的是以Application启动,能运行。。

解决:

先clean,rentApp,在build rentApp。。这样的问题一般都是maven构建的问题。不断的去clean,rebuild。

问题2.

项目打包的时候,在服务器上运行,有提示找不到rentModule 里面的类,找不到里面的方法。。

解决:

先clean rentModel,然后编译rentModel。然后打包rentModel,然后上传到本地仓库。最后在打包rentApp 就ok了。

以上的打包,编译全部都是 通过maven 实现的

Paste_Image.png

以上就是我在搭建多模块的spring boot项目 遇到的问题。。折腾了 百度了很多都没找到靠谱的方案。

上一篇 下一篇

猜你喜欢

热点阅读