Spring Boot开启的2种方式
来源:互联网 发布:c语言转义字符怎么用 编辑:程序博客网 时间:2024/05/23 13:23
Spring Boot依赖
使用Spring Boot很简单,先添加基础依赖包,有以下两种方式
1. 继承spring-boot-starter-parent项目
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version></parent>
2. 导入spring-boot-dependencies项目依赖
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.5.6.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency></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 with <scope>import</scope> you have to redefine the artifact yourself instead of overriding the property.
Spring Boot依赖包里面的组件的版本都是和当前Spring Boot绑定的,如果要修改里面组件的版本,只需要添加如下属性覆盖即可,但这种方式只对继承有效,导入的方式无效。
<properties> <slf4j.version>1.7.25<slf4j.version></properties>
如果导入的方式要实现版本的升级,达到上面的效果,这样也可以做到,把要升级的组件依赖放到Spring Boot之前。
<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>1.5.6.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies></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文件编辑器中编译报错,所以使用继承方式有诸多问题,坑要慢慢趟。
推荐阅读
什么是Spring Boot?
Spring Boot开启的2种方式
Spring Boot Starters启动器
Spring Boot定制启动图案
Spring Boot核心配置
Spring Boot功能实战
Spring Boot自动配置原理、实战
Spring Boot Runner启动器
Spring Boot - Profile不同环境配置
看完有没有收获?分享到朋友圈给更多的人吧。
- Spring Boot开启的2种方式
- spring开启注解的三种方式
- Spring Boot的三种启动方式
- 使用Spring Boot的两种方式
- Spring Boot 开启AOP的方法
- 如何开启Spring Boot的开发模式?
- Spring Boot Session共享2种方式
- Spring Boot Session共享2种方式
- Spring Boot开启https
- spring boot的发布方式
- spring security 注解@EnableGlobalMethodSecurity的三种开启注解方式
- Spring Boot 注解启动的两种方式
- Spring-boot中读取config配置文件的两种方式
- Spring-boot中读取config配置文件的两种方式
- spring boot data redis的三种配置方式
- Spring Boot 快速搭建的三种方式
- Spring Boot 注解启动的两种方式
- 设置Spring Boot上下文(ServletContext)的三种方式
- Spring Boot核心配置
- 依赖
- Spring Boot定制启动图案
- Spring Boot功能实战
- POJ 3370 Halloween treats【鸽巢原理】
- Spring Boot开启的2种方式
- 使用FileUtils简化你的文件操作
- Curl操作
- Spring Boot Runner启动器
- Eclipse代替Oracle接管Java EE
- Intellij Idea非常6的10个姿势!
- 细数Intellij Idea10个蛋疼问题!
- 一分钟开启Tomcat https支持
- 省市二级及联动(省市对应数组)