我喜欢在maven中通过创建如下模块来配置我的应用程序;
<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作为父母。
发布于 2013-12-23 00:08:16
您不必使用spring-boot-starter-parent,这只是一种快速入门的方法。它所提供的都是依赖管理和插件管理。你可以自己做这两件事,如果你想要半途而废的话,你可以使用spring-boot-dependencies (或者等价的父类)来管理依赖项。要做到这一点,可以像这样使用scope=import
<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>发布于 2015-07-29 16:37:21
另一种替代方法是在父pom中包含spring boot的父声明,如此post所示
示例-应用程序pom.xml:
<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:
<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)。
https://stackoverflow.com/questions/20731158
复制相似问题