首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用spring-boot的Maven模块

使用spring-boot的Maven模块
EN

Stack Overflow用户
提问于 2013-12-22 23:51:51
回答 2查看 16.8K关注 0票数 35

我喜欢在maven中通过创建如下模块来配置我的应用程序;

代码语言:javascript
复制
<groupId>com.app</groupId>
<artifactId>example-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
    <module>app-api</module>
    <module>app-impl</module>
    <module>app-web</module>
</modules>

然后,这些模块使用'example-app‘作为父模块。

现在我想对我的web应用程序使用'spring-boot‘。

有没有办法配置maven,使我的'app-web‘是一个spring-boot应用程序?

我面临的问题是,你必须使用spring-boot作为父母。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-23 00:08:16

您不必使用spring-boot-starter-parent,这只是一种快速入门的方法。它所提供的都是依赖管理和插件管理。你可以自己做这两件事,如果你想要半途而废的话,你可以使用spring-boot-dependencies (或者等价的父类)来管理依赖项。要做到这一点,可以像这样使用scope=import

代码语言:javascript
复制
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <type>pom</type>
            <version>1.0.2.RELEASE</version>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
票数 56
EN

Stack Overflow用户

发布于 2015-07-29 16:37:21

另一种替代方法是在父pom中包含spring boot的父声明,如此post所示

示例-应用程序pom.xml:

代码语言:javascript
复制
<project>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.5.RELEASE</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    // rest of the example-app pom declarations
</project>

在此之后,在模块pom (app-web、app-impl等)中,您可以将example-app声明为parent,但现在您可以像在常规项目中那样包含starter依赖项。

app-web pom.xml:

代码语言:javascript
复制
<project>
    <parent>
        <groupId>org.demo</groupId>
        <artifactId>example-app</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <name>app-web</name>
    <artifactId>app-web</artifactId>
    <version>1.0-SNAPSHOT</version> 
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>org.demo</groupId>
            <artifactId>app-api</artifactId>
            <version>1.0-SNAPSHOT</version> 
        </dependency>
        <dependency>
            <groupId>org.demo</groupId>
            <artifactId>app-impl</artifactId>
            <version>1.0-SNAPSHOT</version> 
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    // rest of the app-web pom declarations
</project>

关于版本管理,我在这些示例中使用的并不完全是最佳实践,但由于这超出了问题的范围,因此我跳过了dependencyManagement和parent属性的使用。

此外,如果每个模块中都使用了starter,则可以在父pom中声明依赖项,然后所有模块都将继承它(例如spring-boot-starter-test)。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20731158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档