【问题标题】:Multi Module Project with maven in SpringSpring中带有maven的多模块项目
【发布时间】:2018-12-29 10:48:16
【问题描述】:

我有一个带有 maven 的 Spring Boot 项目,它有 5 个模块和 1 个父模块。

模块结构

 <modules>
    <module>service-app</module>
    <module>admin-app</module>
    <module>service-api</module>
    <module>admin-api</module>
    <module>mail-api</module>
    <module>storage-api</module>
</modules>



    1. admin-app = {<dependency>
            <groupId>com.example</groupId>
            <artifactId>service-api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>storage-api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>mail-api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
}
 2. service-api={
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>storage-api</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
}
 3. service-app={
<dependency>
            <groupId>com.example</groupId>
            <artifactId>service-api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>storage-api</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>mail-api</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
}

我尝试添加新模块并且我已经创建,但是当我运行程序时它返回错误。我的新模块名为 storage-api,它的 application.properties 文件中有一些配置参数。当我想在 storage-api 类中使用它们时。使用 @Value 注释它没有看到它们。 在这种情况下我该如何解决它的问题

【问题讨论】:

    标签: spring maven spring-boot microservices multi-module


    【解决方案1】:

    没有信息很难猜测,但我假设您的模块pom.xml 需要引用其父模块pom.xml,例如:

     <parent>
        <artifactId>your parent</artifactId>
        <groupId>com.example</groupId>
        <version>parent version</version>
    </parent>
    

    只需从工作中查找即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-31
      • 1970-01-01
      • 2010-10-29
      • 1970-01-01
      • 1970-01-01
      • 2017-07-06
      • 2015-10-10
      • 2013-12-15
      相关资源
      最近更新 更多