我把所有Java相关的面试题和答案都整理成了PDF,并且带书签目录,阅读起来非常方便
面试题及答案PDF下载:https://www.hicxy.com/?p=2645
面试题及答案PDF下载:https://www.hicxy.com/?p=2645
面试题及答案PDF下载:https://www.hicxy.com/?p=2645
1. Spring Boot 的核心注解是哪个?它主要由哪几个注解组成的?
启动类上面的注解是@SpringBootApplication,它也是 Spring Boot 的核心注解,主要组合包含了以下 3 个注解:
@SpringBootConfiguration: 组合了 @Configuration 注解,实现配置文件的功能。
@EnableAutoConfiguration: 打开自动配置的功能,也可以关闭某个自动配置的选项,如关闭数据源自动配置功能:@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })。
@ComponentScan: Spring组件扫描。
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n12" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: "Roboto Mono", "Source Sans Pro", "Microsoft YaHei", 微软雅黑 !important; font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: inherit; position: relative !important; width: inherit; -webkit-font-smoothing: initial; line-height: 1.55rem; word-wrap: normal; color: var(--mid-10); margin: 1.8rem 0px 2rem !important; background-position: inherit inherit; background-repeat: inherit inherit;">@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
@Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {</pre>
2. 什么是YAML?
3. 运行 Spring Boot 有哪几种方式?
4. springboot自动配置的原理
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n33" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: "Roboto Mono", "Source Sans Pro", "Microsoft YaHei", 微软雅黑 !important; font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: inherit; position: relative !important; width: inherit; -webkit-font-smoothing: initial; line-height: 1.55rem; word-wrap: normal; color: var(--mid-10); margin: 1.8rem 0px 2rem !important; background-position: inherit inherit; background-repeat: inherit inherit;">@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import(AutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration
</pre>
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n36" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: "Roboto Mono", "Source Sans Pro", "Microsoft YaHei", 微软雅黑 !important; font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: inherit; position: relative !important; width: inherit; -webkit-font-smoothing: initial; line-height: 1.55rem; word-wrap: normal; color: var(--mid-10); margin: 1.8rem 0px 2rem !important; background-position: inherit inherit; background-repeat: inherit inherit;">@Override
public String[] selectImports(AnnotationMetadata annotationMetadata) {
if (!isEnabled(annotationMetadata)) {
return NO_IMPORTS;
}
// 获取配置的元数据
AutoConfigurationMetadata autoConfigurationMetadata = AutoConfigurationMetadataLoader
.loadMetadata(this.beanClassLoader);
// 这个方法包含了加载的主要逻辑,它能找到所有自动注入的类
AutoConfigurationEntry autoConfigurationEntry = getAutoConfigurationEntry(
autoConfigurationMetadata, annotationMetadata);
return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());
}
</pre>
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n39" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: "Roboto Mono", "Source Sans Pro", "Microsoft YaHei", 微软雅黑 !important; font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: inherit; position: relative !important; width: inherit; -webkit-font-smoothing: initial; line-height: 1.55rem; word-wrap: normal; color: var(--mid-10); margin: 1.8rem 0px 2rem !important; background-position: inherit inherit; background-repeat: inherit inherit;">protected AutoConfigurationEntry getAutoConfigurationEntry(
AutoConfigurationMetadata autoConfigurationMetadata,
AnnotationMetadata annotationMetadata) {
// ....
// 获取候选配置类
List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes);
// ... 过滤、去重、排除一些配置类
return new AutoConfigurationEntry(configurations, exclusions);
}
</pre>
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n45" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: "Roboto Mono", "Source Sans Pro", "Microsoft YaHei", 微软雅黑 !important; font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: inherit; position: relative !important; width: inherit; -webkit-font-smoothing: initial; line-height: 1.55rem; word-wrap: normal; color: var(--mid-10); margin: 1.8rem 0px 2rem !important; background-position: inherit inherit; background-repeat: inherit inherit;">...
Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=
org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,
...
</pre>
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="java" cid="n48" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: "Roboto Mono", "Source Sans Pro", "Microsoft YaHei", 微软雅黑 !important; font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: inherit; position: relative !important; width: inherit; -webkit-font-smoothing: initial; line-height: 1.55rem; word-wrap: normal; color: var(--mid-10); margin: 1.8rem 0px 2rem !important; background-position: inherit inherit; background-repeat: inherit inherit;">org.springframework.boot.autoconfigure.EnableAutoConfiguration=
org.yuan.interview.springboot.XXXAutoConfiguration</pre>