add spring-boot-modules to maven project
spring boot 项目中 多modules parent 冲突
如果一个maven project 建立多modules ,pom文件应该是这样:
<groupId>cn.ifengkou</groupId>
<artifactId>spring-cloud-test</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>spring-boot-test</module>
<module>spring-cloud-config</module>
</modules>
module 的pom文件应该是这样:
<parent>
<artifactId>spring-cloud-test</artifactId>
<groupId>cn.ifengkou</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-test</artifactId>
大家在一开始学spring-boot时,都应该看过 官网的quick start项目,里面pom文件也有一个parent
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
这样,modules 项目中的 要继承父项目,而spring boot 又要继承spring-boot-starter-parent,一个pom文件不能存在两个parent,这个问题怎么解决呢?
网上提供了一种方式,通过在子module 的parent 中,加 ../pom.xml 节点,实现父项目依赖管理的继承。但这种方式违背了按需加载依赖的理念,并不可取
#project(parent) pom
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<modules>
<module>dao</module>
</modules>
# module pom
<parent>
<artifactId>parent</artifactId>
<groupId>com.luyh.projectv1</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
其实spring-boot-starter-parent 只是一种快速开始spring boot 的方式,没必要非要用它,它所做的只是提供依赖管理和plugin管理(dependency management and plugin management),我们也可以自己做这些,当然如果想省事,spring 也提供了 spring-boot-dependencies 这个依赖(等价于 parent) 去管理依赖项,要实现同样的效果,你只需要用 scope=import, 像下面例子:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
完整pom.xml,或者查看githubspring-cloud-test
#project(parent) pom
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.ifengkou</groupId>
<artifactId>spring-cloud-test</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>spring-boot-test</module>
<module>spring-cloud-config</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring.boot.version>1.5.2.RELEASE</spring.boot.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
# module pom
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-cloud-test</artifactId>
<groupId>cn.ifengkou</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-test</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
add spring-boot-modules to maven project的更多相关文章
- spring boot + swagger + mysql + maven
1.首先编写 yaml 文件,创建项目所需的接口,在swagger.io官网上生成 spring boot项目: 2.由于生成的spring boot项目是公共类的所以还需要修改成所需的项目名称,主要 ...
- [Spring Boot 系列] 集成maven和Spring boot的profile 专题
maven中配置profile节点: <project> .... <profiles> <profile> <!-- 生产环境 --> <id& ...
- Spring Boot 笔记 (1) - Maven、基本配置、Profile的使用
一. Spring Boot 简介 开箱即用的一站式 Java EE 解决方案 Spring 技术栈的大整合 核心问题 暂时无法回答 Spring Boot 和 SOA 有什么区别? Spring B ...
- [Spring Boot 系列] 集成maven和Spring boot的profile功能
由于项目的需要, 今天给spirng boot项目添加了profile功能.再网上搜索了一圈,也没有找到满意的参考资料,其实配置并不难,就是没有一个one stop(一站式)讲解的地方,所以有了写这篇 ...
- spring boot 项目添加maven依赖时provided
spring boot 项目是自带tomcat 的,但是我们有时候是需要把项目打包成war 然后放到独立的tomcat中运行的,这个时候我们就需要将它自带的tomcat给排除开,这时候我们就可以使用& ...
- Spring Boot入门简介-Maven配置
一.简介 -- 简化Spring应用开发的一个框架: -- 整个Spring技术栈的一个大整合: -- J2EE开发的一站式解决方案. 二.背景: ① J2EE笨重的开发.繁多的配置.低下的开发效率. ...
- spring boot++jpa+ mysql +maven
项目结构图: 一. 添加mysql 配置 1 在pom.xml中添加 maven依赖 <!--mysql--> <dependency> <groupId>mysq ...
- MAC系统下用Idea创建spring boot工程 基于maven
1.创建项目 打开idea编辑器,选择file -> new -> project 点击next 依次填入group,artifact 填写完成之后再点击“next” 根据自己的需求在最 ...
- 在spring boot上基于maven使用redis——批量匹配并删除 (二)
一.背景 在搭建了项目之后,由于需要通过触发动作,并删除redis中多个key. 二.思路 在查询了jedis并没有类似的删除方法之后,事情就变得清晰起来.完成上述任务,分为两个步骤,第一,找到要删除 ...
- spring boot项目的maven库查询地址
阿里巴巴地址 http://maven.aliyun.com/nexus/#welcome maven通用地址 http://mvnrepository.com/ gradle默认mavenCentr ...
随机推荐
- PDO控制、连接数据库
PDO(PHP Data Objects)是一种在PHP里连接数据库的使用接口.PDO与mysqli曾经被建议用来取代原本PHP在用的mysql相关函数,基于数据库使用的安全性,因为后者欠缺对于SQL ...
- 卷积神经网络(CNN)反向传播算法
在卷积神经网络(CNN)前向传播算法中,我们对CNN的前向传播算法做了总结,基于CNN前向传播算法的基础,我们下面就对CNN的反向传播算法做一个总结.在阅读本文前,建议先研究DNN的反向传播算法:深度 ...
- 裸机(Bare Metal)安装CoreOS
本文以 1235.9.0-stable 为例,在WMWare中进行安装. 1.获取安装资源 https://coreos.com/releases/ 通过"Browse Images&quo ...
- centOS7 mini配置linux服务器(三) 配置防火墙以及IPtables切换
一.firewall介绍 CentOS 7中防火墙是一个非常的强大的功能,在CentOS 6.5中在iptables防火墙中进行了升级了. 1.官方介绍 The dynamic firewall da ...
- Django|第一部
Django · Django流程 · Django url · Django view · Django form ①:Django流程介绍 MTV模式 注明的MVC模式:所谓MVC就是把web应用 ...
- weui.css中flex容器下子项目的水平和垂直居中
想用weui.css写微信平台的页面,发现没有让flex(weui-flex)容器下,子项目(weui-flex__item)居中的类. 百度了一下,是用justify-content:center; ...
- (2)写给Web初学者的教案-----让我们开始准备学习
课前准备 我们将会从零基础带领大家一步一步的学习Web前端技术,这个零基础是什么概念呢?你只要具备以下技能就可以学习: 一.个人学习条件(必备) 会开关电脑,手机.(哇塞,任老师你逗我们吧!). 会打 ...
- Android OkHttp使用与分析
安卓开发领域,很多重要的问题都有了很好的开源解决方案,例如网络请求 OkHttp + Retrofit 简直就是不二之选."我们不重复造轮子不表示我们不需要知道轮子该怎么造及如何更好的造!& ...
- Java基础——深入理解Java中的final关键字(转载)
Java中的final关键字非常重要,它可以应用于类.方法以及变量.这篇文章中我将带你看看什么是final关键字?将变量,方法和类声明为final代表了什么?使用final的好处是什么?最后也有一些使 ...
- 动力IT教育背后的“神秘力量”
IT行业作为当前就业形势最好的行业,成为大多数毕业生以及转行人群的首选.且国家也对互联网大力支持,IT行业市场需求空缺也越来越大,随之IT培训机构也如雨后春笋般,层出不穷. 行业易选,但该如何选择培训 ...