Spring Boot开启的2种方式

12 篇文章 0 订阅

Spring Boot开启的2种方式

原创: javastack Java技术栈 Java技术栈

微信号 javastack

功能介绍 专注分享Java技术干货,包括多线程、JVM、Spring Boot、Spring Cloud、Intellij IDEA、Dubbo、Zookeeper、Redis、架构设计、微服务、消息队列、Git、面试题、程序员攻略、最新动态等。

2017-08-28

 

Spring Boot依赖

使用Spring Boot很简单,先添加基础依赖包,有以下两种方式

1. 继承spring-boot-starter-parent项目

 
  1. <parent>

  2.    <groupId>org.springframework.boot</groupId>

  3.    <artifactId>spring-boot-starter-parent</artifactId>

  4.    <version>1.5.6.RELEASE</version>

  5. </parent>

2. 导入spring-boot-dependencies项目依赖

 
  1. <dependencyManagement>

  2.    <dependencies>

  3.        <dependency>

  4.            <groupId>org.springframework.boot</groupId>

  5.            <artifactId>spring-boot-dependencies</artifactId>

  6.            <version>1.5.6.RELEASE</version>

  7.            <type>pom</type>

  8.            <scope>import</scope>

  9.        </dependency>

  10. </dependencyManagement>

 

Spring Boot依赖注意点

1. 属性覆盖只对继承有效

This only works if your Maven project inherits (directly or indirectly) from spring-boot-dependencies. If you have added spring-boot-dependencies in your own dependencyManagement section withimportyou have to redefine the artifact yourself instead of overriding the property.

Spring Boot依赖包里面的组件的版本都是和当前Spring Boot绑定的,如果要修改里面组件的版本,只需要添加如下属性覆盖即可,但这种方式只对继承有效,导入的方式无效。

 
  1. <properties>

  2.    <slf4j.version>1.7.25<slf4j.version>

  3. </properties>

如果导入的方式要实现版本的升级,达到上面的效果,这样也可以做到,把要升级的组件依赖放到Spring Boot之前。

 
  1. <dependencyManagement>

  2.    <dependencies>

  3.        <!-- Override Spring Data release train provided by Spring Boot -->

  4.        <dependency>

  5.            <groupId>org.springframework.data</groupId>

  6.            <artifactId>spring-data-releasetrain</artifactId>

  7.            <version>Fowler-SR2</version>

  8.            <scope>import</scope>

  9.            <type>pom</type>

  10.        </dependency>

  11.        <dependency>

  12.            <groupId>org.springframework.boot</groupId>

  13.            <artifactId>spring-boot-dependencies</artifactId>

  14.            <version>1.5.6.RELEASE</version>

  15.            <type>pom</type>

  16.            <scope>import</scope>

  17.        </dependency>

  18.    </dependencies>

  19. </dependencyManagement>

Each Spring Boot release is designed and tested against a specific set of third-party dependencies. Overriding versions may cause compatibility issues.

需要注意,要修改Spring Boot的依赖组件版本可能会造成不兼容的问题。

2. 资源文件过滤问题

使用继承Spring Boot时,如果要使用Maven resource filter过滤资源文件时,资源文件里面的占位符为了使${}和Spring Boot区别开来,此时要用@...@包起来,不然无效。另外,@...@占位符在yaml文件编辑器中编译报错,所以使用继承方式有诸多问题,坑要慢慢趟。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值