Java 岗位必备技能 SpringBoot 的 9 道面试题集锦
当下 SpringBoot 框架真的很火,大多数企业把它作为基础技能,考察求职者的能力。如下截图,是我从 Boss 直聘中找到的,要求 SpringBoot 是必备技能。



所以非常有必要为了面试,好好归纳下 SpringBoot 常被提起来的问题。
题目大纲如下:
什么是 SpringBoot?
SpringBoot 与 Spring、Spring MVC 之间有什么关系?
使用 SpringBoot 有什么优势?
SpringBoot 默认的配置文件是什么?
如何根据 SpringBoot 项目所处的环境,定义不同的配置?
解释下 SpringBoot 的核心注解 @SpringBootApplication 的组成
开启 SpringBoot 特性的两种方式?
SpringBoot 项目如何兼容 Spring 的配置
SpringBoot 的读取放置在不同目录下的配置文件,优先级是怎样的?
什么是 SpringBoot?
SpringBoot 是建立在现有 Spring 框架之上,使开发人员简化 Spring 项目开发,降低使用成本。
SpringBoot 与 Spring、Spring MVC 之间有什么关系?
Spring 的全称是 Spring Framework。
Spring MVC 是 Spring Framework 的子模块。
而 SpringBoot 是构造在 Spring Framework 之上的 Boot 启动器。
使用 SpringBoot 有什么优势?
内嵌常用应用服务器,比如 Tomcat、Jetty 等,不用单独再配置应用服务器,并且不用打成 war 包
可以以 jar 包的形式,快速独立运行项目
在 maven 的 pom.xml 配置文件中提供了 Starters,而不需要到处找依赖包,避免了大量依赖的导入以及版本之间的冲突与不兼容
SpringBoot 默认的配置文件是什么?
默认配置文件是项目根目录下的 application.properties 或者 application.yml 文件。
如何根据 SpringBoot 项目所处的环境,定义不同的配置?
我们可以在主配置文件 application.properties 之外,再新增如下文件,满足不同环境的要求:
开发环境:application-dev.properties
测试环境:application-test.properties
生产环境:application-prop.properties
如果需要激活某个环境的配置,只需在主配置文件 application.properties 指定项目所在环境的标识,配置内容如下:
解释下 SpringBoot 的核心注解 @SpringBootApplication 的组成

它包含以下 3 个重要的注解:
@ComponentScan
该注解实现 Spring 组件的扫描。
@EnableAutoConfiguration
该注解能够让 SpringBoot 打开自动配置的功能。
@SpringBootConfiguration
该注解实现配置文件的功能。
开启 SpringBoot 特性的两种方式?
继承 spring-boot-starter-parent 项目
导入 spring-boot-dependencies 依赖
实际开发中,推荐使用第二种方式。因为如果我们创建的项目已经存在自己的父级项目,会与第一种方式存在冲突。
SpringBoot 项目如何兼容 Spring 的配置
在启动类中添加:

SpringBoot 的读取放置在不同目录下的配置文件,优先级是怎样的?
配置文件具体可以放置在如下目录,按被读取的优先级由高到低排列:
假如项目中存在两个及以上的这样的目录,等级高的会覆盖掉比它低的配置文件。

为了方便给大家准备了非常全的一套 SpringBoot 一线大厂面试题。全面覆盖 BATJ 等一线互联网公司的面试题及解答,由 BAT 一线互联网公司大牛带你深度剖析面试题背后的原理,不仅授你以鱼,更授你以渔,为你面试扫除一切障碍。资料已整理成文档,需要获取的小伙伴可以+ VX: mxk6072






评论