Spring Boot 之Maven配置
来源:互联网 发布:少儿编程培训班靠谱吗 编辑:程序博客网 时间:2024/06/05 16:52
Maven users can inherit from the spring-boot-starter-parent project to obtain sensible defaults. The parent project provides the following features:
- Java 1.8 as the default compiler level.
- UTF-8 source encoding.
- A Dependency Management section, allowing you to omit tags for common dependencies, inherited from the spring-boot-dependencies POM.
- Sensible resource filtering.
- Sensible plugin configuration (exec plugin, surefire, Git commit ID, shade).
- Sensible resource filtering for application.properties and application.yml including profile-specific files (e.g. application-foo.properties and application-foo.yml)
- On the last point: since the default config files accept Spring style placeholders (${…}) the Maven filtering is changed to use @..@ placeholders (you can override that with a Maven property resource.delimiter).
Inheriting the starter parent
To configure your project to inherit from the spring-boot-starter-parent simply set the parent:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.M1</version></parent>
You should only need to specify the Spring Boot version number on this dependency. If you import additional starters, you can safely omit the version number.
With that setup, you can also override individual dependencies by overriding a property in your own project. For instance, to upgrade to another Spring Data release train you’d add the following to your pom.xml.
<properties> <spring-data-releasetrain.version>Fowler-SR2</spring-data-releasetrain.version></properties>
Check the spring-boot-dependencies pom for a list of supported properties.
Using Spring Boot without the parent POM
Not everyone likes inheriting from the spring-boot-starter-parent POM. You may have your own corporate standard parent that you need to use, or you may just prefer to explicitly declare all your Maven configuration.
If you don’t want to use the spring-boot-starter-parent, you can still keep the benefit of the dependency management (but not the plugin management) by using a scope=import dependency:
<dependencyManagement> <dependencies> <dependency> <!-- Import dependency management from Spring Boot --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.0.0.M1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies></dependencyManagement>
That setup does not allow you to override individual dependencies using a property as explained above. To achieve the same result, you’d need to add an entry in the dependencyManagement of your project before the spring-boot-dependencies entry. For instance, to upgrade to another Spring Data release train you’d add the following to your pom.xml.
<dependencyManagement> <dependencies> <!-- Override Spring Data release train provided by Spring Boot --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-releasetrain</artifactId> <version>Fowler-SR2</version> <scope>import</scope> <type>pom</type> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.0.0.M1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies></dependencyManagement>
你可通过在pom.xml中指定Parent标签来获取默认设置
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.M1</version></parent>
当然了,如果你不想继承使用spring-boot-starter-parent的一些默认设置,你可以通过dependencyManagement标签来显示声明Maven配置。
<dependencyManagement> <dependencies> <dependency> <!-- Import dependency management from Spring Boot --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.0.0.M1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies></dependencyManagement>
在这种配置下,如果你需要重写或者升级某个项目依赖,你需要在pom.xml中的spring-boot-dependencies标签前添加对应的依赖:
<dependencyManagement> <dependencies> <!-- Override Spring Data release train provided by Spring Boot --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-releasetrain</artifactId> <version>Fowler-SR2</version> <scope>import</scope> <type>pom</type> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.0.0.M1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies></dependencyManagement>
参考链接
阅读全文
0 0
- Spring Boot 之Maven配置
- Spring Boot实战之Maven
- 关于spring boot配置maven文件配置
- Spring Boot之日志配置
- Spring-Boot之基础 POM 文件和自动配置(maven)
- Spring Boot实战之Spring基础配置
- [spring学习] 之 spring-boot 默认配置
- spring boot maven 插件
- maven构建Spring Boot
- spring boot maven集成
- 初识spring boot maven管理--属性文件配置
- intellij idea + bitbucket + maven + spring-boot配置记录
- spring-boot+maven运行和调试的配置
- Spring Boot+Maven 工程配置h2内存数据库
- Spring Boot+Maven 工程配置H2内存数据库
- Maven/Gradle 在Spring Boot中配置log4j
- Maven构建Spring Boot+Mybatis+derby的配置
- Spring Boot maven配置环境部署及定义相关属性
- Android设置全屏显示
- linux---注意事项
- typescript中使用字典Dictionary
- IO/输入输出
- Centos 7配置JDK1.8_第一节
- Spring Boot 之Maven配置
- Springmvc rest 传递json报415错误(The server refused this request because the request entity is in a forma
- 算法导论程序29--二叉搜索树的插入和删除(Python)
- sourceinsight 4.0 编码乱码修改
- playbook语法和命令
- 0628Blog总集
- 嵌入式面试题
- Paxos理解
- 每日AC -- 主对角线打印二维数组---美团点评2016研发工程师编程题(二)