<!doctype html>Spring Boot 源码阅读2
figure:last-child { margin-bottom: 0.5rem; }
#write ol, #write ul { position: relative; }
img { max-width: 100%; vertical-align: middle; }
button, input, select, textarea { color: inherit; font: inherit; }
input[type="checkbox"], input[type="radio"] { line-height: normal; padding: 0px; }
*, ::after, ::before { box-sizing: border-box; }
#write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write p, #write pre { width: inherit; }
#write h1, #write h2, #write h3, #write h4, #write h5, #write h6, #write p { position: relative; }
p { line-height: inherit; }
h1, h2, h3, h4, h5, h6 { break-after: avoid-page; break-inside: avoid; orphans: 2; }
p { orphans: 4; }
h1 { font-size: 2rem; }
h2 { font-size: 1.8rem; }
h3 { font-size: 1.6rem; }
h4 { font-size: 1.4rem; }
h5 { font-size: 1.2rem; }
h6 { font-size: 1rem; }
.md-math-block, .md-rawblock, h1, h2, h3, h4, h5, h6, p { margin-top: 1rem; margin-bottom: 1rem; }
.hidden { display: none; }
.md-blockmeta { color: rgb(204, 204, 204); font-weight: 700; font-style: italic; }
a { cursor: pointer; }
sup.md-footnote { padding: 2px 4px; background-color: rgba(238, 238, 238, 0.7); color: rgb(85, 85, 85); border-radius: 4px; cursor: pointer; }
sup.md-footnote a, sup.md-footnote a:hover { color: inherit; text-transform: inherit; text-decoration: inherit; }
#write input[type="checkbox"] { cursor: pointer; width: inherit; height: inherit; }
figure { overflow-x: auto; margin: 1.2em 0px; max-width: calc(100% + 16px); padding: 0px; }
figure > table { margin: 0px !important; }
tr { break-inside: avoid; break-after: auto; }
thead { display: table-header-group; }
table { border-collapse: collapse; border-spacing: 0px; width: 100%; overflow: auto; break-inside: auto; text-align: left; }
table.md-table td { min-width: 32px; }
.CodeMirror-gutters { border-right: 0px; background-color: inherit; }
.CodeMirror-linenumber { user-select: none; }
.CodeMirror { text-align: left; }
.CodeMirror-placeholder { opacity: 0.3; }
.CodeMirror pre { padding: 0px 4px; }
.CodeMirror-lines { padding: 0px; }
div.hr:focus { cursor: none; }
#write pre { white-space: pre-wrap; }
#write.fences-no-line-wrapping pre { white-space: pre; }
#write pre.ty-contain-cm { white-space: normal; }
.CodeMirror-gutters { margin-right: 4px; }
.md-fences { font-size: 0.9rem; display: block; break-inside: avoid; text-align: left; overflow: visible; white-space: pre; background: inherit; position: relative !important; }
.md-diagram-panel { width: 100%; margin-top: 10px; text-align: center; padding-top: 0px; padding-bottom: 8px; overflow-x: auto; }
#write .md-fences.mock-cm { white-space: pre-wrap; }
.md-fences.md-fences-with-lineno { padding-left: 0px; }
#write.fences-no-line-wrapping .md-fences.mock-cm { white-space: pre; overflow-x: auto; }
.md-fences.mock-cm.md-fences-with-lineno { padding-left: 8px; }
.CodeMirror-line, twitterwidget { break-inside: avoid; }
.footnotes { opacity: 0.8; font-size: 0.9rem; margin-top: 1em; margin-bottom: 1em; }
.footnotes + .footnotes { margin-top: 0px; }
.md-reset { margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: top; background: 0px 0px; text-decoration: none; text-shadow: none; float: none; position: static; width: auto; height: auto; white-space: nowrap; cursor: inherit; -webkit-tap-highlight-color: transparent; line-height: normal; font-weight: 400; text-align: left; box-sizing: content-box; direction: ltr; }
li div { padding-top: 0px; }
blockquote { margin: 1rem 0px; }
li .mathjax-block, li p { margin: 0.5rem 0px; }
li { margin: 0px; position: relative; }
blockquote > :last-child { margin-bottom: 0px; }
blockquote > :first-child, li > :first-child { margin-top: 0px; }
.footnotes-area { color: rgb(136, 136, 136); margin-top: 0.714rem; padding-bottom: 0.143rem; white-space: normal; }
#write .footnote-line { white-space: pre-wrap; }
@media print {
body, html { border: 1px solid transparent; height: 99%; break-after: avoid; break-before: avoid; }
#write { margin-top: 0px; padding-top: 0px; border-color: transparent !important; }
.typora-export * { -webkit-print-color-adjust: exact; }
html.blink-to-pdf { font-size: 13px; }
.typora-export #write { padding-left: 32px; padding-right: 32px; padding-bottom: 0px; break-after: avoid; }
.typora-export #write::after { height: 0px; }
}
.footnote-line { margin-top: 0.714em; font-size: 0.7em; }
a img, img a { cursor: pointer; }
pre.md-meta-block { font-size: 0.8rem; min-height: 0.8rem; white-space: pre-wrap; background: rgb(204, 204, 204); display: block; overflow-x: hidden; }
p > .md-image:only-child:not(.md-img-error) img, p > img:only-child { display: block; margin: auto; }
p > .md-image:only-child { display: inline-block; width: 100%; }
#write .MathJax_Display { margin: 0.8em 0px 0px; }
.md-math-block { width: 100%; }
.md-math-block:not(:empty)::after { display: none; }
[contenteditable="true"]:active, [contenteditable="true"]:focus, [contenteditable="false"]:active, [contenteditable="false"]:focus { outline: 0px; box-shadow: none; }
.md-task-list-item { position: relative; list-style-type: none; }
.task-list-item.md-task-list-item { padding-left: 0px; }
.md-task-list-item > input { position: absolute; top: 0px; left: 0px; margin-left: -1.2em; margin-top: calc(1em - 10px); border: none; }
.math { font-size: 1rem; }
.md-toc { min-height: 3.58rem; position: relative; font-size: 0.9rem; border-radius: 10px; }
.md-toc-content { position: relative; margin-left: 0px; }
.md-toc-content::after, .md-toc::after { display: none; }
.md-toc-item { display: block; color: rgb(65, 131, 196); }
.md-toc-item a { text-decoration: none; }
.md-toc-inner:hover { text-decoration: underline; }
.md-toc-inner { display: inline-block; cursor: pointer; }
.md-toc-h1 .md-toc-inner { margin-left: 0px; font-weight: 700; }
.md-toc-h2 .md-toc-inner { margin-left: 2em; }
.md-toc-h3 .md-toc-inner { margin-left: 4em; }
.md-toc-h4 .md-toc-inner { margin-left: 6em; }
.md-toc-h5 .md-toc-inner { margin-left: 8em; }
.md-toc-h6 .md-toc-inner { margin-left: 10em; }
@media screen and (max-width: 48em) {
.md-toc-h3 .md-toc-inner { margin-left: 3.5em; }
.md-toc-h4 .md-toc-inner { margin-left: 5em; }
.md-toc-h5 .md-toc-inner { margin-left: 6.5em; }
.md-toc-h6 .md-toc-inner { margin-left: 8em; }
}
a.md-toc-inner { font-size: inherit; font-style: inherit; font-weight: inherit; line-height: inherit; }
.footnote-line a:not(.reversefootnote) { color: inherit; }
.md-attr { display: none; }
.md-fn-count::after { content: "."; }
code, pre, samp, tt { font-family: var(--monospace); }
kbd { margin: 0px 0.1em; padding: 0.1em 0.6em; font-size: 0.8em; color: rgb(36, 39, 41); background: rgb(255, 255, 255); border: 1px solid rgb(173, 179, 185); border-radius: 3px; box-shadow: rgba(12, 13, 14, 0.2) 0px 1px 0px, rgb(255, 255, 255) 0px 0px 0px 2px inset; white-space: nowrap; vertical-align: middle; }
.md-comment { color: rgb(162, 127, 3); opacity: 0.8; font-family: var(--monospace); }
code { text-align: left; vertical-align: initial; }
a.md-print-anchor { white-space: pre !important; border-width: initial !important; border-style: none !important; border-color: initial !important; display: inline-block !important; position: absolute !important; width: 1px !important; right: 0px !important; outline: 0px !important; background: 0px 0px !important; text-decoration: initial !important; text-shadow: initial !important; }
.md-inline-math .MathJax_SVG .noError { display: none !important; }
.html-for-mac .inline-math-svg .MathJax_SVG { vertical-align: 0.2px; }
.md-math-block .MathJax_SVG_Display { text-align: center; margin: 0px; position: relative; text-indent: 0px; max-width: none; max-height: none; min-height: 0px; min-width: 100%; width: auto; overflow-y: hidden; display: block !important; }
.MathJax_SVG_Display, .md-inline-math .MathJax_SVG_Display { width: auto; margin: inherit; display: inline-block !important; }
.MathJax_SVG .MJX-monospace { font-family: var(--monospace); }
.MathJax_SVG .MJX-sans-serif { font-family: sans-serif; }
.MathJax_SVG { display: inline; font-style: normal; font-weight: 400; line-height: normal; zoom: 90%; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; }
.MathJax_SVG * { transition: none 0s ease 0s; }
.MathJax_SVG_Display svg { vertical-align: middle !important; margin-bottom: 0px !important; margin-top: 0px !important; }
.os-windows.monocolor-emoji .md-emoji { font-family: "Segoe UI Symbol", sans-serif; }
.md-diagram-panel > svg { max-width: 100%; }
[lang="flow"] svg, [lang="mermaid"] svg { max-width: 100%; height: auto; }
[lang="mermaid"] .node text { font-size: 1rem; }
table tr th { border-bottom: 0px; }
video { max-width: 100%; display: block; margin: 0px auto; }
iframe { max-width: 100%; width: 100%; border: none; }
.highlight td, .highlight tr { border: 0px; }
svg[id^="mermaidChart"] { line-height: 1em; }
mark { background: rgb(255, 255, 0); color: rgb(0, 0, 0); }
.md-html-inline .md-plain, .md-html-inline strong, mark .md-inline-math, mark strong { color: inherit; }
mark .md-meta { color: rgb(0, 0, 0); opacity: 0.3 !important; }
.CodeMirror { height: auto; }
.CodeMirror.cm-s-inner { background: inherit; }
.CodeMirror-scroll { overflow: auto hidden; z-index: 3; }
.CodeMirror-gutter-filler, .CodeMirror-scrollbar-filler { background-color: rgb(255, 255, 255); }
.CodeMirror-gutters { border-right: 1px solid rgb(221, 221, 221); background: inherit; white-space: nowrap; }
.CodeMirror-linenumber { padding: 0px 3px 0px 5px; text-align: right; color: rgb(153, 153, 153); }
.cm-s-inner .cm-keyword { color: rgb(119, 0, 136); }
.cm-s-inner .cm-atom, .cm-s-inner.cm-atom { color: rgb(34, 17, 153); }
.cm-s-inner .cm-number { color: rgb(17, 102, 68); }
.cm-s-inner .cm-def { color: rgb(0, 0, 255); }
.cm-s-inner .cm-variable { color: rgb(0, 0, 0); }
.cm-s-inner .cm-variable-2 { color: rgb(0, 85, 170); }
.cm-s-inner .cm-variable-3 { color: rgb(0, 136, 85); }
.cm-s-inner .cm-string { color: rgb(170, 17, 17); }
.cm-s-inner .cm-property { color: rgb(0, 0, 0); }
.cm-s-inner .cm-operator { color: rgb(152, 26, 26); }
.cm-s-inner .cm-comment, .cm-s-inner.cm-comment { color: rgb(170, 85, 0); }
.cm-s-inner .cm-string-2 { color: rgb(255, 85, 0); }
.cm-s-inner .cm-meta { color: rgb(85, 85, 85); }
.cm-s-inner .cm-qualifier { color: rgb(85, 85, 85); }
.cm-s-inner .cm-builtin { color: rgb(51, 0, 170); }
.cm-s-inner .cm-bracket { color: rgb(153, 153, 119); }
.cm-s-inner .cm-tag { color: rgb(17, 119, 0); }
.cm-s-inner .cm-attribute { color: rgb(0, 0, 204); }
.cm-s-inner .cm-header, .cm-s-inner.cm-header { color: rgb(0, 0, 255); }
.cm-s-inner .cm-quote, .cm-s-inner.cm-quote { color: rgb(0, 153, 0); }
.cm-s-inner .cm-hr, .cm-s-inner.cm-hr { color: rgb(153, 153, 153); }
.cm-s-inner .cm-link, .cm-s-inner.cm-link { color: rgb(0, 0, 204); }
.cm-negative { color: rgb(221, 68, 68); }
.cm-positive { color: rgb(34, 153, 34); }
.cm-header, .cm-strong { font-weight: 700; }
.cm-del { text-decoration: line-through; }
.cm-em { font-style: italic; }
.cm-link { text-decoration: underline; }
.cm-error { color: red; }
.cm-invalidchar { color: red; }
.cm-constant { color: rgb(38, 139, 210); }
.cm-defined { color: rgb(181, 137, 0); }
div.CodeMirror span.CodeMirror-matchingbracket { color: rgb(0, 255, 0); }
div.CodeMirror span.CodeMirror-nonmatchingbracket { color: rgb(255, 34, 34); }
.cm-s-inner .CodeMirror-activeline-background { background: inherit; }
.CodeMirror { position: relative; overflow: hidden; }
.CodeMirror-scroll { height: 100%; outline: 0px; position: relative; box-sizing: content-box; background: inherit; }
.CodeMirror-sizer { position: relative; }
.CodeMirror-gutter-filler, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-vscrollbar { position: absolute; z-index: 6; display: none; }
.CodeMirror-vscrollbar { right: 0px; top: 0px; overflow: hidden; }
.CodeMirror-hscrollbar { bottom: 0px; left: 0px; overflow: hidden; }
.CodeMirror-scrollbar-filler { right: 0px; bottom: 0px; }
.CodeMirror-gutter-filler { left: 0px; bottom: 0px; }
.CodeMirror-gutters { position: absolute; left: 0px; top: 0px; padding-bottom: 30px; z-index: 3; }
.CodeMirror-gutter { white-space: normal; height: 100%; box-sizing: content-box; padding-bottom: 30px; margin-bottom: -32px; display: inline-block; }
.CodeMirror-gutter-wrapper { position: absolute; z-index: 4; background: 0px 0px !important; border: none !important; }
.CodeMirror-gutter-background { position: absolute; top: 0px; bottom: 0px; z-index: 4; }
.CodeMirror-gutter-elt { position: absolute; cursor: default; z-index: 4; }
.CodeMirror-lines { cursor: text; }
.CodeMirror pre { border-radius: 0px; border-width: 0px; background: 0px 0px; font-family: inherit; font-size: inherit; margin: 0px; white-space: pre; overflow-wrap: normal; color: inherit; z-index: 2; position: relative; overflow: visible; }
.CodeMirror-wrap pre { overflow-wrap: break-word; white-space: pre-wrap; word-break: normal; }
.CodeMirror-code pre { border-right: 30px solid transparent; width: fit-content; }
.CodeMirror-wrap .CodeMirror-code pre { border-right: none; width: auto; }
.CodeMirror-linebackground { position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px; z-index: 0; }
.CodeMirror-linewidget { position: relative; z-index: 2; overflow: auto; }
.CodeMirror-wrap .CodeMirror-scroll { overflow-x: hidden; }
.CodeMirror-measure { position: absolute; width: 100%; height: 0px; overflow: hidden; visibility: hidden; }
.CodeMirror-measure pre { position: static; }
.CodeMirror div.CodeMirror-cursor { position: absolute; visibility: hidden; border-right: none; width: 0px; }
.CodeMirror div.CodeMirror-cursor { visibility: hidden; }
.CodeMirror-focused div.CodeMirror-cursor { visibility: inherit; }
.cm-searching { background: rgba(255, 255, 0, 0.4); }
@media print {
.CodeMirror div.CodeMirror-cursor { visibility: hidden; }
}
:root {
--side-bar-bg-color: #fafafa;
--control-text-color: #777;
}
@include-when-export url(https://fonts.loli.net/css?family=Open+Sans:400italic,700italic,700,400&subset=latin,latin-ext);
html {
font-size: 16px;
}
body {
font-family: "Open Sans","Clear Sans","Helvetica Neue",Helvetica,Arial,sans-serif;
color: rgb(51, 51, 51);
line-height: 1.6;
}
#write {
max-width: 860px;
margin: 0 auto;
padding: 30px;
padding-bottom: 100px;
}
#write > ul:first-child,
#write > ol:first-child{
margin-top: 30px;
}
a {
color: #4183C4;
}
h1,
h2,
h3,
h4,
h5,
h6 {
position: relative;
margin-top: 1rem;
margin-bottom: 1rem;
font-weight: bold;
line-height: 1.4;
cursor: text;
}
h1:hover a.anchor,
h2:hover a.anchor,
h3:hover a.anchor,
h4:hover a.anchor,
h5:hover a.anchor,
h6:hover a.anchor {
text-decoration: none;
}
h1 tt,
h1 code {
font-size: inherit;
}
h2 tt,
h2 code {
font-size: inherit;
}
h3 tt,
h3 code {
font-size: inherit;
}
h4 tt,
h4 code {
font-size: inherit;
}
h5 tt,
h5 code {
font-size: inherit;
}
h6 tt,
h6 code {
font-size: inherit;
}
h1 {
padding-bottom: .3em;
font-size: 2.25em;
line-height: 1.2;
border-bottom: 1px solid #eee;
}
h2 {
padding-bottom: .3em;
font-size: 1.75em;
line-height: 1.225;
border-bottom: 1px solid #eee;
}
h3 {
font-size: 1.5em;
line-height: 1.43;
}
h4 {
font-size: 1.25em;
}
h5 {
font-size: 1em;
}
h6 {
font-size: 1em;
color: #777;
}
p,
blockquote,
ul,
ol,
dl,
table{
margin: 0.8em 0;
}
li>ol,
li>ul {
margin: 0 0;
}
hr {
height: 2px;
padding: 0;
margin: 16px 0;
background-color: #e7e7e7;
border: 0 none;
overflow: hidden;
box-sizing: content-box;
}
li p.first {
display: inline-block;
}
ul,
ol {
padding-left: 30px;
}
ul:first-child,
ol:first-child {
margin-top: 0;
}
ul:last-child,
ol:last-child {
margin-bottom: 0;
}
blockquote {
border-left: 4px solid #dfe2e5;
padding: 0 15px;
color: #777777;
}
blockquote blockquote {
padding-right: 0;
}
table {
padding: 0;
word-break: initial;
}
table tr {
border-top: 1px solid #dfe2e5;
margin: 0;
padding: 0;
}
table tr:nth-child(2n),
thead {
background-color: #f8f8f8;
}
table tr th {
font-weight: bold;
border: 1px solid #dfe2e5;
border-bottom: 0;
margin: 0;
padding: 6px 13px;
}
table tr td {
border: 1px solid #dfe2e5;
margin: 0;
padding: 6px 13px;
}
table tr th:first-child,
table tr td:first-child {
margin-top: 0;
}
table tr th:last-child,
table tr td:last-child {
margin-bottom: 0;
}
.CodeMirror-lines {
padding-left: 4px;
}
.code-tooltip {
box-shadow: 0 1px 1px 0 rgba(0,28,36,.3);
border-top: 1px solid #eef2f2;
}
.md-fences,
code,
tt {
border: 1px solid #e7eaed;
background-color: #f8f8f8;
border-radius: 3px;
padding: 0;
padding: 2px 4px 0px 4px;
font-size: 0.9em;
}
code {
background-color: #f3f4f4;
padding: 0 2px 0 2px;
}
.md-fences {
margin-bottom: 15px;
margin-top: 15px;
padding-top: 8px;
padding-bottom: 6px;
}
.md-task-list-item > input {
margin-left: -1.3em;
}
@media print {
html {
font-size: 13px;
}
table,
pre {
page-break-inside: avoid;
}
pre {
word-wrap: break-word;
}
}
.md-fences {
background-color: #f8f8f8;
}
#write pre.md-meta-block {
padding: 1rem;
font-size: 85%;
line-height: 1.45;
background-color: #f7f7f7;
border: 0;
border-radius: 3px;
color: #777777;
margin-top: 0 !important;
}
.mathjax-block>.code-tooltip {
bottom: .375rem;
}
.md-mathjax-midline {
background: #fafafa;
}
#write>h3.md-focus:before{
left: -1.5625rem;
top: .375rem;
}
#write>h4.md-focus:before{
left: -1.5625rem;
top: .285714286rem;
}
#write>h5.md-focus:before{
left: -1.5625rem;
top: .285714286rem;
}
#write>h6.md-focus:before{
left: -1.5625rem;
top: .285714286rem;
}
.md-image>.md-meta {
/*border: 1px solid #ddd;*/
border-radius: 3px;
padding: 2px 0px 0px 4px;
font-size: 0.9em;
color: inherit;
}
.md-tag {
color: #a7a7a7;
opacity: 1;
}
.md-toc {
margin-top:20px;
padding-bottom:20px;
}
.sidebar-tabs {
border-bottom: none;
}
#typora-quick-open {
border: 1px solid #ddd;
background-color: #f8f8f8;
}
#typora-quick-open-item {
background-color: #FAFAFA;
border-color: #FEFEFE #e5e5e5 #e5e5e5 #eee;
border-style: solid;
border-width: 1px;
}
/** focus mode */
.on-focus-mode blockquote {
border-left-color: rgba(85, 85, 85, 0.12);
}
header, .context-menu, .megamenu-content, footer{
font-family: "Segoe UI", "Arial", sans-serif;
}
.file-node-content:hover .file-node-icon,
.file-node-content:hover .file-node-open-state{
visibility: visible;
}
.mac-seamless-mode #typora-sidebar {
background-color: #fafafa;
background-color: var(--side-bar-bg-color);
}
.md-lang {
color: #b4654d;
}
.html-for-mac .context-menu {
--item-hover-bg-color: #E6F0FE;
}
#md-notification .btn {
border: 0;
}
.dropdown-menu .divider {
border-color: #e5e5e5;
}
.ty-preferences .window-content {
background-color: #fafafa;
}
.ty-preferences .nav-group-item.active {
color: white;
background: #999;
}
-->
目录
目录1 SpringBoot启动关键点解析1.1 new SpringApplication(primarySources)部分1.2 run(args)部分1.2.1 ConfigurableEnvironment提供的服务(关注的信息)1.2.2 ConfigurableApplicationContext1.2.3 SpringApplication.prepareContext1.2.4 SpringApplication.refreshContext1.2.4.1 AbstractApplicationContext.finishBeanFactoryInitialization1.2.4.2 DefaultListableBeanFactory.preInstantiateSingletons1.2.5 默认的关闭钩子1.3 启动日志分析1.3.1 虚拟机启动日志打印1.3.2 Banner打印1.3.3 环境信息打印1.3.4 web服务启动日志1.3.5 实例化相关信息打印1.3.6 web启动打印1.3.7 启动成功日志
1 SpringBoot启动关键点解析
启动核心分为两部分new SpringApplication(primarySources)和执行run(args)方法,
1.1 new SpringApplication(primarySources)部分
部分的核心是从META/spring.facteries中读取ApplicationContextInitializer和ApplicationListener配置,然后直接通过反射实例化,实例化+排序完毕后,把应用初始化器ApplicationContextInitializer和应用监听放到SpringApplication对象上
1.2 run(args)部分
run部分最核心的构建ConfigurableApplicationContext这个上下文对象对象,构建完毕后当前线程是会返回的。
run方法实现为:
x
/**
* Run the Spring application, creating and refreshing a new
* {@link ApplicationContext}.
* @param args the application arguments (usually passed from a Java main method)
* @return a running {@link ApplicationContext}
*/
public ConfigurableApplicationContext run(String... args) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
ConfigurableApplicationContext context = null;
Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList<>();
configureHeadlessProperty();
SpringApplicationRunListeners listeners = getRunListeners(args);//获取SpringApplicationRunListener的监听,当前只有org.springframework.boot.context.event.EventPublishingRunListener一个
listeners.starting(); //调度监听的start方法,这里事件发布监听的start方法是发布了一个ApplicationStartingEvent事件
try {
ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
//创建一个ConfigurableEnvironment(理解参见1.2.1),初始化
//让configurationProperties的属性源始终位于第一(应该是保证最高优先级)
//调度应用监听执行environmentPrepared, EventPublishingRunListener一个也就是发布一个ApplicationEnvironmentPreparedEvent事件
//将获取到的environment中的spring.main配置绑定到SpringApplication的source中(这部分用到了一个Binder语法,没有看懂)
ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments);
// 从环境中读取spring.beaninfo.ignore并设置为系统属性
configureIgnoreBeanInfo(environment);
//Banner打印
Banner printedBanner = printBanner(environment);
//创建ConfigurableApplicationContext对象,这个上下文对象关注的信息有点多,参见(1.2.2)
context = createApplicationContext();
//从META_DATA/spring.facteries中读取SpringBootExceptionReporter的配置并进行实例化,默认读取出来是org.springframework.boot.diagnostics.FailureAnalyzers
exceptionReporters = getSpringFactoriesInstances(SpringBootExceptionReporter.class,
new Class[] { ConfigurableApplicationContext.class }, context);
//准备环境,参见(1.2.3),主要为设置上下文对象的容器属性
//调度一开始读取的initializer的执行initialize方法,之后调度监听器的contextPrepared,发布ApplicationContextInitializedEvent
//打印开始和profile的日志
//把拿到的标签类进行beanDefinition注册,之后调度监听器的contextLoaded,发布ApplicationPreparedEvent
prepareContext(context, environment, listeners, applicationArguments, printedBanner);
//刷新上下文,参见(1.2.4),
refreshContext(context);
afterRefresh(context, applicationArguments);
stopWatch.stop();
if (this.logStartupInfo) {
//打印已启动信息以及耗时情况
new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), stopWatch);
}
//调度监听器的started的方法,此处默认为发布一个ApplicationStartedEvent事件
listeners.started(context);
//找注册的ApplicationRunner、CommandLineRunner,排序后分别调度对应的ApplicationRunner和CommandLineRunner (spring-boot的启动后自动执行建表语句好像就是通过这个机制实现。这里可以做一些启动后就需要立马执行的事)。注意,此时刚发布ApplicationStartedEvent而尚未发布ApplicationReadyEvent
callRunners(context, applicationArguments);
}
catch (Throwable ex) {
handleRunFailure(context, ex, exceptionReporters, listeners);
throw new IllegalStateException(ex);
}
?
try {
//调度监听器的running方法,此处默认为发布一个ApplicationReadyEvent事件。
//执行完次应该代表服务正式可用
listeners.running(context);
}
catch (Throwable ex) {
handleRunFailure(context, ex, exceptionReporters, null);
throw new IllegalStateException(ex);
}
return context;
}
1.2.1 ConfigurableEnvironment提供的服务(关注的信息)
从环境接口的方法来看,它主要关注与当前应用的profile、propertySource、systemEnvironment、systemProperties、getConversionService;环境本身重要的信息有webApplicationType(ConversionService是干啥的??)
1.2.2 ConfigurableApplicationContext
从名字解读是可配置的应用容器对象。关注的内容非常多,包括应用监听器(ApplicationListener)、应用的后置处理器(PosProcessor)、应用的协议解析器(ProtocolResolver)、bean管理、类加载器、环境对象管理(Environment)、消息对象管理(Message)、资源对象管理(Resouce)等.
容器对象是根据应用类型有所不同的,SERVLET创建的是org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext的容器对象,该对象在构造时会构造一个AnnotatedBeanDefinitionReader和ClassPathBeanDefinitionScanner对象。
AnnotatedBeanDefinitionReader对象同时设置了beanFactory的dependencyComparator、autowireCandidateResolver实例,进行了ConfigurationClassPostProcessor、AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、EventListenerMethodProcessor、DefaultEventListenerFactory的bean声明。
ClassPathBeanDefinitionScanner对象创建时同时TypeFilter的实例(包含AnnotationTypeFilter(Component.class))
1.2.3 SpringApplication.prepareContext
代码如下:
xxxxxxxxxx
private void prepareContext(ConfigurableApplicationContext context, ConfigurableEnvironment environment,
SpringApplicationRunListeners listeners, ApplicationArguments applicationArguments, Banner printedBanner) {
context.setEnvironment(environment);
//把SpringApplication上的部分信息绑定到context上
postProcessApplicationContext(context);
//拿到之前从配置中读取并实例化的initializer,执行initialize(context)方法 !!它们大部分都是给容器设置一些值
applyInitializers(context);
//调度监听器的contextPrepared,此处为发布一个ApplicationContextInitializedEvent事件
listeners.contextPrepared(context);
if (this.logStartupInfo) {
//打印应用启动的日志
logStartupInfo(context.getParent() == null);
//打印profile加载情况
logStartupProfileInfo(context);
}
// Add boot specific singleton beans
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
//把ApplicationArguments注册成单例bean
beanFactory.registerSingleton("springApplicationArguments", applicationArguments);
if (printedBanner != null) {
//如果Banner非空,也注册成单例bean
beanFactory.registerSingleton("springBootBanner", printedBanner);
}
if (beanFactory instanceof DefaultListableBeanFactory) {
//设置bean工程的allowBeanDefinitionOverriding属性
((DefaultListableBeanFactory) beanFactory)
.setAllowBeanDefinitionOverriding(this.allowBeanDefinitionOverriding);
}
if (this.lazyInitialization) {
//如果是lazyInitialization模式(默认为false),给上下文追加一个LazyInitializationBeanFactoryPostProcessor的后置处理器实例
context.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor());
}
// Load the sources -》注册的入口类被识别为私有源,需要加入更多的标签类看看是否是在这里就已经被全部识别
Set<Object> sources = getAllSources();
Assert.notEmpty(sources, "Sources must not be empty");
//把识别出来的源都进行beanDefinition注册
load(context, sources.toArray(new Object[0]));
//调度监听器的contextLoaded方法,这里表现为发布一个ApplicationPreparedEvent事件
listeners.contextLoaded(context);
}
默认读取并实例化的初始化器有:
0 = {[email protected]} 1 = {[email protected]} 2 = {[email protected]} 3 = {[email protected]} 4 = {[email protected]} 5 = {[email protected]} 6 = {[email protected]}
1.2.4 SpringApplication.refreshContext
private void refreshContext(ConfigurableApplicationContext context) {
refresh(context);
if (this.registerShutdownHook) {
try {
//注册关闭虚拟机的钩子
context.registerShutdownHook();
}
catch (AccessControlException ex) {
// Not allowed in some environments.
}
}
}
?
protected void refresh(ApplicationContext applicationContext) {
Assert.isInstanceOf(AbstractApplicationContext.class, applicationContext);
((AbstractApplicationContext) applicationContext).refresh();
}
?
//AbstractApplicationContext.refresh
@Override
public void refresh() throws BeansException, IllegalStateException {
synchronized (this.startupShutdownMonitor) {
// Prepare this context for refreshing. //初始化当前容器的一些属性
prepareRefresh();
?
// Tell the subclass to refresh the internal bean factory. //设置工厂的序列化id
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
?
// Prepare the bean factory for use in this context.
//初始化beanFactory的一些属性,创建一些实例类,也注册了几个beanDefinition
//设置内容包括 beanClassLoader、StandardBeanExpressionResolver、ResourceEditorRegistrar、ApplicationContextAwareProcessor
//设置忽略的依赖接口EnvironmentAware、EmbeddedValueResolverAware、ResourceLoaderAware、ApplicationEventPublisherAware、MessageSourceAware、ApplicationContextAware
//注册BeanFactory(SpringApplication)、ResourceLoader(ConfigurableApplicationContext)、ApplicationEventPublisher(ConfigurableApplicationContext)、ApplicationContext(ConfigurableApplicationContext)
//追加beanPostProcessors:ApplicationListenerDetector
//管控environment、systemProperties、systemEnvironment单例
prepareBeanFactory(beanFactory);
?
try {
// Allows post-processing of the bean factory in context subclasses.
//设置一个WebApplicationContextServletContextAwareProcessor后置处理器
//设置忽略接口依赖ServletContextAware
//注册并实例化register和session的Scope,在注册过程中通过WebApplicationContextUtils.registerWebApplicationScopes(getBeanFactory());跳转到sprig-web中
//注册ServletRequest、ServletResponse、HttpSession、WebRequest的解析以来
//!!!注意,也就这里引入了对于spring-web的支持 (spring-boot通过spring-boot-starter..等是引入了spring-web的...)
//这里总结就是注册了spring-web相关的信息
postProcessBeanFactory(beanFactory);
?
// Invoke factory processors registered as beans in the context.
//先是收集beanFactory中直接已经注册好的BeanDefinitionRegistryPostProcessor,按registryProcessors、regularPostProcessors两种类别收集,在所有BeanDefinitionRegistryPostProcessor类后置执行方法最后执行,最后先执行按registryProcessors再执行regularPostProcessors
//然后从bean定义集合中找是BeanDefinitionRegistryPostProcessor类别,同时带PriorityOrdered标签的,实例化后执行后置方法
//再从bean定义集合中找是BeanDefinitionRegistryPostProcessor类别,同时带Ordered标签的,实例化后执行后置方法
//最后执行其余没有被实例化的BeanDefinitionRegistryPostProcessor,实例化并执行
//然后处理BeanFactoryPostProcessor类别
//按PriorityOrdered、Ordered、其他来收集并实例化BeanFactoryPostProcessor
//之后是分别排序和执行PriorityOrdered、Ordered、其他 类别的BeanFactoryPostProcessor
invokeBeanFactoryPostProcessors(beanFactory);
?
// Register bean processors that intercept bean creation.
//处理BeanPostProcessor,按PriorityOrdered、Ordered、其他来收集并实例化和执行
registerBeanPostProcessors(beanFactory);
?
// Initialize message source for this context.
//如果有名为messageSource的bean以它作为上下文里的messageSource,否则新建一个DelegatingMessageSource注册单例,并以它作为messageSource
initMessageSource();
?
// Initialize event multicaster for this context.
//如果有名为applicationEventMulticaster的bean以它作为上下文的applicationEventMulticaster,否则新建一个SimpleApplicationEventMulticaster注册单例,并以它作为applicationEventMulticaster
initApplicationEventMulticaster();
?
// Initialize other special beans in specific context subclasses.
//如果有名为themeSource的bean以它作为web抽象层级的themeSource,否则新建一个
//找容器里的ServletWebServerFactory(这里找到的是tomcatServletWebServerFactory),把它实例化并通过这个工厂创建webServer(这部分还是用spring-boot里的TomcatServletWebServerFactory)
//(!!!后续可以深入一下这里,看一下如何创建一个内嵌的tomcat,以及如何以代码的角度来理解这个tomcat容器)
//创建完毕后,更新对应PropertySource
onRefresh();
?
// Check for listener beans and register them.
//拿到applicationEventMulticaster,把之前收录的applicationListeners注册上(注册实例)
//并且从bean容器中找ApplicationListener类别的bean定义,也注册上(注册beanName)
//拿到earlyApplicationEvents,广播事件
registerListeners();
?
// Instantiate all remaining (non-lazy-init) singletons.
//看(1.2.4.1)的源码解读,bean实例化部分并没有深入
finishBeanFactoryInitialization(beanFactory);
?
// Last step: publish corresponding event.
//清理临时缓存
//如果有名为lifecycleProcessor的bean以它作为上下文的lifecycleProcessor,否则创建一个DefaultLifecycleProcessor,并执行startBeans方法;标记其running=true
//发布一个ContextRefreshedEvent事件
//处理了一个spring.liveBeansView.mbeanDomain相关服务(这里没理解)
//启动webServer
finishRefresh();
}
?
catch (BeansException ex) {
if (logger.isWarnEnabled()) {
logger.warn("Exception encountered during context initialization - " +
"cancelling refresh attempt: " + ex);
}
?
// Destroy already created singletons to avoid dangling resources.
destroyBeans();
?
// Reset ‘active‘ flag.
cancelRefresh(ex);
?
// Propagate exception to caller.
throw ex;
}
?
finally {
// Reset common introspection caches in Spring‘s core, since we
// might not ever need metadata for singleton beans anymore...
resetCommonCaches();
}
}
}
?
1.2.4.1 AbstractApplicationContext.finishBeanFactoryInitialization
源码如下:
xxxxxxxxxx
/**
* Finish the initialization of this context‘s bean factory,
* initializing all remaining singleton beans.
*/
protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) {
// Initialize conversion service for this context.
if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME) &&
beanFactory.isTypeMatch(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)) {
beanFactory.setConversionService(
beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class));
}
?
// Register a default embedded value resolver if no bean post-processor
// (such as a PropertyPlaceholderConfigurer bean) registered any before:
// at this point, primarily for resolution in annotation attribute values.
if (!beanFactory.hasEmbeddedValueResolver()) {
beanFactory.addEmbeddedValueResolver(strVal -> getEnvironment().resolvePlaceholders(strVal));
}
?
// Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early.
//如果有对应bean定义,【先】创建一个LoadTimeWeaverAware的bean
String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false);
for (String weaverAwareName : weaverAwareNames) {
getBean(weaverAwareName);
}
?
// Stop using the temporary ClassLoader for type matching.
//清空临时的类加载器
beanFactory.setTempClassLoader(null);
?
// Allow for caching all bean definition metadata, not expecting further changes.
//这里的意思是冻结beanDefinition,不预期后面还有beanDefinition相关改动
beanFactory.freezeConfiguration();
?
// Instantiate all remaining (non-lazy-init) singletons.
//实例化所有有beanDefinition定义但是尚未实例化的bean(具体参见1.2.4.2)
beanFactory.preInstantiateSingletons();
}
1.2.4.2 DefaultListableBeanFactory.preInstantiateSingletons
大部分的bean实例化就是在这个环节,细节非常复杂,这里并没有深入
xxxxxxxxxx
@Override
public void preInstantiateSingletons() throws BeansException {
if (logger.isTraceEnabled()) {
logger.trace("Pre-instantiating singletons in " + this);
}
?
// Iterate over a copy to allow for init methods which in turn register new bean definitions.
// While this may not be part of the regular factory bootstrap, it does otherwise work fine.
List<String> beanNames = new ArrayList<>(this.beanDefinitionNames);
?
// Trigger initialization of all non-lazy singleton beans...
for (String beanName : beanNames) {
RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);
if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) {
if (isFactoryBean(beanName)) {
Object bean = getBean(FACTORY_BEAN_PREFIX + beanName);
if (bean instanceof FactoryBean) {
final FactoryBean<?> factory = (FactoryBean<?>) bean;
boolean isEagerInit;
if (System.getSecurityManager() != null && factory instanceof SmartFactoryBean) {
isEagerInit = AccessController.doPrivileged((PrivilegedAction<Boolean>)
((SmartFactoryBean<?>) factory)::isEagerInit,
getAccessControlContext());
}
else {
isEagerInit = (factory instanceof SmartFactoryBean &&
((SmartFactoryBean<?>) factory).isEagerInit());
}
if (isEagerInit) {
getBean(beanName);
}
}
}
else {
//这里的实现非常复杂
//创建bean的实际过程(后续专门开章节再深入吧)
//比如bean依赖(dependsOn)、bean实例化时的后置处理(InstantiationAwareBeanPostProcessor)等都是在这里面完成
getBean(beanName);
}
}
}
1.2.5 默认的关闭钩子
钩子注册是通过
x
private void refreshContext(ConfigurableApplicationContext context) {
refresh(context);
if (this.registerShutdownHook) {
try {
context.registerShutdownHook(); //注册钩子
}
catch (AccessControlException ex) {
// Not allowed in some environments.
}
}
}
具体代码为:(只是定义了一个独立线程,在执行结束时才进行调度)
xxxxxxxxxx
@Override
public void registerShutdownHook() {
if (this.shutdownHook == null) {
// No shutdown hook registered yet.
this.shutdownHook = new Thread(SHUTDOWN_HOOK_THREAD_NAME) {
@Override
public void run() {
synchronized (startupShutdownMonitor) {
doClose();
}
}
};
Runtime.getRuntime().addShutdownHook(this.shutdownHook);
}
}
具体代码如下,注意注释里说的 “Called by both {@code close()} and a JVM shutdown hook, if any.”
x
/**
* Actually performs context closing: publishes a ContextClosedEvent and
* destroys the singletons in the bean factory of this application context.
* <p>Called by both {@code close()} and a JVM shutdown hook, if any.
* @see org.springframework.context.event.ContextClosedEvent
* @see #destroyBeans()
* @see #close()
* @see #registerShutdownHook()
*/
protected void doClose() {
// Check whether an actual close attempt is necessary...
if (this.active.get() && this.closed.compareAndSet(false, true)) { //断点是走不到这里的..
if (logger.isDebugEnabled()) {
logger.debug("Closing " + this);
}
?
LiveBeansView.unregisterApplicationContext(this);
?
try {
// Publish shutdown event.
//发布一个ContextClosedEvent事件
publishEvent(new ContextClosedEvent(this));
}
catch (Throwable ex) {
logger.warn("Exception thrown from ApplicationListener handling ContextClosedEvent", ex);
}
?
// Stop all Lifecycle beans, to avoid delays during individual destruction.
if (this.lifecycleProcessor != null) {
try {
//这里貌似是通过生命周期管理停掉所有在执行的bean (TODO 生命周期管理机制是啥?),并设置lifecycleProcessor.running=false
this.lifecycleProcessor.onClose();
}
catch (Throwable ex) {
logger.warn("Exception thrown from LifecycleProcessor on context close", ex);
}
}
?
// Destroy all cached singletons in the context‘s BeanFactory.
//销毁所有beanFactory中缓存的单例bean
destroyBeans();
?
//销毁beanFactory工厂
// Close the state of this context itself.
closeBeanFactory();
?
// Let subclasses do some final clean-up if they wish...
onClose();
?
// Reset local application listeners to pre-refresh state.
if (this.earlyApplicationListeners != null) {
this.applicationListeners.clear();
this.applicationListeners.addAll(this.earlyApplicationListeners);
}
?
// Switch to inactive.
this.active.set(false);
}
}
1.3 启动日志分析
1.3.1 虚拟机启动日志打印
日志显示:
xxxxxxxxxx
Connected to the target VM, address: ‘127.0.0.1:59163‘, transport: ‘socket‘
1.3.2 Banner打印
日志显示:
xxxxxxxxxx
. ____ _ __ _ _
/\\ / ___‘_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | ‘_ | ‘_| | ‘_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
‘ |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.5.RELEASE)
打印相关代码:
Banner printedBanner = printBanner(environment);
堆栈:
run:310, SpringApplication (org.springframework.boot)
run:1226, SpringApplication (org.springframework.boot)
run:1215, SpringApplication (org.springframework.boot)
main:11, DemoApplication (com.example.demo)
1.3.3 环境信息打印
日志显示:
xxxxxxxxxx
2020-03-20 11:26:35.800 INFO 22748 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on WIN-89EHFNGT2HI with PID 22748 (D:\workspace_gw\code\demo-simple-web\target\classes started by Administrator in D:\workspace_gw\code\demo-simple-web)
2020-03-20 11:26:35.803 INFO 22748 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
打印相关代码:
xxxxxxxxxx
if (this.logStartupInfo) {
logStartupInfo(context.getParent() == null);
logStartupProfileInfo(context);
}
堆栈
xxxxxxxxxx
prepareContext:373, SpringApplication (org.springframework.boot)
run:314, SpringApplication (org.springframework.boot)
run:1226, SpringApplication (org.springframework.boot)
run:1215, SpringApplication (org.springframework.boot)
main:11, DemoApplication (com.example.demo)
1.3.4 web服务启动日志
xxxxxxxxxx
2020-03-20 11:33:27.604 INFO 8740 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-03-20 11:33:27.661 INFO 8740 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-03-20 11:33:27.663 INFO 8740 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.31]
2020-03-20 11:33:28.328 INFO 8740 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-03-20 11:33:28.329 INFO 8740 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 15341 ms
打印相关方法:
createWebServer();
堆栈:
onRefresh:153, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context)
refresh:544, AbstractApplicationContext (org.springframework.context.support)
refresh:141, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context)
refresh:747, SpringApplication (org.springframework.boot)
refreshContext:397, SpringApplication (org.springframework.boot)
run:315, SpringApplication (org.springframework.boot)
run:1226, SpringApplication (org.springframework.boot)
run:1215, SpringApplication (org.springframework.boot)
main:11, DemoApplication (com.example.demo)
1.3.5 实例化相关信息打印
这里只是默认spring-boot-web的一个实例的打印
日志显示:
xxxxxxxxxx
2020-03-20 11:36:29.536 INFO 21876 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService ‘applicationTaskExecutor‘
打印相关方法:
x
if (logger.isInfoEnabled()) {
logger.info("Initializing ExecutorService" + (this.beanName != null ? " ‘" + this.beanName + "‘" : ""));
}
堆栈:
xxxxxxxxxx
initialize:181, ExecutorConfigurationSupport (org.springframework.scheduling.concurrent)
afterPropertiesSet:173, ExecutorConfigurationSupport (org.springframework.scheduling.concurrent)
invokeInitMethods:1855, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
initializeBean:1792, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
doCreateBean:595, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBean:517, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
lambda$doGetBean$0:323, AbstractBeanFactory (org.springframework.beans.factory.support)
getObject:-1, 124734309 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$143)
getSingleton:222, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support)
doGetBean:321, AbstractBeanFactory (org.springframework.beans.factory.support)
getBean:202, AbstractBeanFactory (org.springframework.beans.factory.support)
configureAsyncSupport:211, WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter (org.springframework.boot.autoconfigure.web.servlet)
configureAsyncSupport:67, WebMvcConfigurerComposite (org.springframework.web.servlet.config.annotation)
configureAsyncSupport:68, DelegatingWebMvcConfiguration (org.springframework.web.servlet.config.annotation)
requestMappingHandlerAdapter:626, WebMvcConfigurationSupport (org.springframework.web.servlet.config.annotation)
requestMappingHandlerAdapter:369, WebMvcAutoConfiguration$EnableWebMvcConfiguration (org.springframework.boot.autoconfigure.web.servlet)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
instantiate:154, SimpleInstantiationStrategy (org.springframework.beans.factory.support)
instantiate:651, ConstructorResolver (org.springframework.beans.factory.support)
instantiateUsingFactoryMethod:636, ConstructorResolver (org.springframework.beans.factory.support)
instantiateUsingFactoryMethod:1338, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBeanInstance:1177, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
doCreateBean:557, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
createBean:517, AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support)
lambda$doGetBean$0:323, AbstractBeanFactory (org.springframework.beans.factory.support)
getObject:-1, 124734309 (org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$143)
getSingleton:222, DefaultSingletonBeanRegistry (org.springframework.beans.factory.support)
doGetBean:321, AbstractBeanFactory (org.springframework.beans.factory.support)
getBean:202, AbstractBeanFactory (org.springframework.beans.factory.support)
preInstantiateSingletons:879, DefaultListableBeanFactory (org.springframework.beans.factory.support)
finishBeanFactoryInitialization:878, AbstractApplicationContext (org.springframework.context.support)
refresh:550, AbstractApplicationContext (org.springframework.context.support)
refresh:141, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context)
refresh:747, SpringApplication (org.springframework.boot)
refreshContext:397, SpringApplication (org.springframework.boot)
run:315, SpringApplication (org.springframework.boot)
run:1226, SpringApplication (org.springframework.boot)
run:1215, SpringApplication (org.springframework.boot)
main:11, DemoApplication (com.example.demo)
1.3.6 web启动打印
日志显示:
xxxxxxxxxx
2020-03-20 11:37:38.186 INFO 21876 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ‘‘
相关方法:
xxxxxxxxxx
if (webServer != null) {
webServer.start();
}
堆栈:
xxxxxxxxxx
startWebServer:297, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context)
finishRefresh:163, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context)
refresh:553, AbstractApplicationContext (org.springframework.context.support)
refresh:141, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context)
refresh:747, SpringApplication (org.springframework.boot)
refreshContext:397, SpringApplication (org.springframework.boot)
run:315, SpringApplication (org.springframework.boot)
run:1226, SpringApplication (org.springframework.boot)
run:1215, SpringApplication (org.springframework.boot)
main:11, DemoApplication (com.example.demo)
1.3.7 启动成功日志
日志显示:
xxxxxxxxxx
2020-03-20 11:38:06.446 INFO 21876 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 168.106 seconds (JVM running for 178.556)
相关代码:
xxxxxxxxxx
if (this.logStartupInfo) {
new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), stopWatch);
}
堆栈:
xxxxxxxxxx
run:321, SpringApplication (org.springframework.boot)
run:1226, SpringApplication (org.springframework.boot)
run:1215, SpringApplication (org.springframework.boot)
main:11, DemoApplication (com.example.demo)
原文地址:https://www.cnblogs.com/ybk2018af/p/12530845.html