{"id":10006972,"date":"2022-12-15T05:45:08","date_gmt":"2022-12-14T21:45:08","guid":{"rendered":"https:\/\/ityet.com\/?p=10006972"},"modified":"2022-12-15T05:45:08","modified_gmt":"2022-12-14T21:45:08","slug":"springboot%e5%86%85%e7%bd%aetomcat%e5%90%af%e5%8a%a8%e8%bf%87%e7%a8%8b%e5%8f%8a%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006972","title":{"rendered":"SpringBoot\u5185\u7f6etomcat\u542f\u52a8\u8fc7\u7a0b\u53ca\u539f\u7406"},"content":{"rendered":"<h3>\u4f5c\u8005\uff1a\u674e\u5ca9\u79d1<\/h3>\n<h3>1 \u80cc\u666f<\/h3>\n<p>SpringBoot \u662f\u4e00\u4e2a\u6846\u67b6\uff0c\u4e00\u79cd\u5168\u65b0\u7684\u7f16\u7a0b\u89c4\u8303\uff0c\u4ed6\u7684\u4ea7\u751f\u7b80\u5316\u4e86\u6846\u67b6\u7684\u4f7f\u7528\uff0c\u540c\u65f6\u4e5f\u63d0\u4f9b\u4e86\u5f88\u591a\u4fbf\u6377\u7684\u529f\u80fd\uff0c\u6bd4\u5982\u5185\u7f6e tomcat \u5c31\u662f\u5176\u4e2d\u4e00\u9879\uff0c\u4ed6\u8ba9\u6211\u4eec\u7701\u53bb\u4e86\u642d\u5efa tomcat \u5bb9\u5668\uff0c\u751f\u6210 war\uff0c\u90e8\u7f72\uff0c\u542f\u52a8 tomcat\u3002\u56e0\u4e3a\u5185\u7f6e\u4e86\u542f\u52a8\u5bb9\u5668\uff0c\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7 Maven \u547d\u4ee4\u5c06\u9879\u76ee\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u7684 jar \u5305\uff0c\u901a\u8fc7 java -jar \u547d\u4ee4\u76f4\u63a5\u542f\u52a8\uff0c\u4e0d\u9700\u8981\u518d\u50cf\u4ee5\u524d\u4e00\u6837\uff0c\u6253\u5305\u6210 War \u5305\uff0c\u7136\u540e\u90e8\u7f72\u5728 Tomcat \u4e2d\u3002\u90a3\u4e48\u5185\u7f6e tomcat \u662f\u5982\u4f55\u5b9e\u73b0\u7684\u5462<\/p>\n<h3>2 tomcat \u542f\u52a8\u8fc7\u7a0b\u53ca\u539f\u7406<\/h3>\n<h4>2.1 \u4e0b\u8f7d\u4e00\u4e2a springboot \u9879\u76ee<\/h4>\n<p>\u5728\u8fd9\u91cc\u4e0b\u8f7d\u4e00\u4e2a\u9879\u76ee\u00a0<a href=\"https:\/\/link.segmentfault.com\/?enc=LYQ38nJlMRiMKq94Phrimw%3D%3D.pyrie%2Be%2B%2FZI2VIj4QsJRyN4R%2F%2FTO3lnLSkWArNL06p1woq486q2vmrws61uX8%2Fc9u44TSyfvIk2rkDkiQa%2FDqOi1gm1v%2F640oubCBedN8Gg%3D\" rel=\"nofollow\">https:\/\/start.spring.io\/<\/a>\u00a0\u4e5f\u53ef\u4ee5\u5728 idea \u65b0\u5efa SpringBoot-Web \u5de5\u7a0b.<\/p>\n<pre><code>&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n<p>\u70b9\u51fb pom.xml \u4f1a\u6709 tomcat \u4f9d\u8d56<\/p>\n<pre><code>&lt;dependency&gt;\n&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n&lt;artifactId&gt;spring-boot-starter-tomcat&lt;\/artifactId&gt;\n&lt;version&gt;2.1.2.RELEASE&lt;\/version&gt;\n&lt;scope&gt;compile&lt;\/scope&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n<h4>2.2 \u4ece\u542f\u52a8\u5165\u53e3\u5f00\u59cb\u4e00\u6b65\u6b65\u63a2\u7d22<\/h4>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029303\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u70b9\u51fb\u8fdb\u5165 run \u65b9\u6cd5<\/p>\n<pre><code>public static ConfigurableApplicationContext run(Class&lt;?&gt; primarySource,\nString... args) {\nreturn run(new Class&lt;?&gt;[] { primarySource }, args);\n}\n\n\/\/\u7ee7\u7eed\u70b9\u51fb\u8fdb\u5165run\u65b9\u6cd5\npublic static ConfigurableApplicationContext run(Class&lt;?&gt;[] primarySources,\nString[] args) {\nreturn new SpringApplication(primarySources).run(args);\n}<\/code><\/pre>\n<p>\u8fdb\u5165\u5230\u8fd9\u4e2a run \u65b9\u6cd5\u4e4b\u540e\u5c31\u53ef\u4ee5\u770b\u5230\uff0c\u6211\u4eec\u8ba4\u8bc6\u7684\u4e00\u4e9b\u521d\u59cb\u5316\u4e8b\u4ef6\u3002\u4e3b\u8981\u7684\u8fc7\u7a0b\u4e5f\u662f\u5728\u8fd9\u91cc\u5b8c\u6210\u7684\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029304\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h4>2.3 \u6e90\u7801\u4ee3\u7801\u6d41\u7a0b\u5927\u81f4\u662f\u8fd9\u6837<\/h4>\n<pre><code>\/**\n* Run the Spring application, creating and refreshing a new\n* {@link ApplicationContext}.\n* @param args the application arguments (usually passed from a Java main method)\n* @return a running {@link ApplicationContext}\n*\/\npublic ConfigurableApplicationContext run(String... args) {\nStopWatch stopWatch = new StopWatch();\nstopWatch.start();\nConfigurableApplicationContext context = null;\nCollection&lt;SpringBootExceptionReporter&gt; exceptionReporters = new ArrayList&lt;&gt;();\n\/**1\u3001\u914d\u7f6e\u7cfb\u7edf\u5c5e\u6027*\/\nconfigureHeadlessProperty();\n\/**2.\u83b7\u53d6\u76d1\u542c\u5668*\/\nSpringApplicationRunListeners listeners = getRunListeners(args);\n\/**\u53d1\u5e03\u5e94\u7528\u5f00\u59cb\u542f\u52a8\u4e8b\u4ef6 *\/\nlisteners.starting();\ntry {\n\/** 3.\u521d\u59cb\u5316\u53c2\u6570 *\/\nApplicationArguments applicationArguments = new DefaultApplicationArguments(\nargs);\n\/** 4.\u914d\u7f6e\u73af\u5883*\/\nConfigurableEnvironment environment = prepareEnvironment(listeners,\napplicationArguments);\n\nconfigureIgnoreBeanInfo(environment);\nBanner printedBanner = printBanner(environment);\n\/**5.\u521b\u5efa\u5e94\u7528\u4e0a\u4e0b\u6587*\/\ncontext = createApplicationContext();\nexceptionReporters = getSpringFactoriesInstances(\nSpringBootExceptionReporter.class,\nnew Class[] { ConfigurableApplicationContext.class }, context);\n\/**6.\u9884\u5904\u7406\u4e0a\u4e0b\u6587*\/\nprepareContext(context, environment, listeners, applicationArguments,\nprintedBanner);\n\n\/**6.\u5237\u65b0\u4e0a\u4e0b\u6587*\/\nrefreshContext(context);\nafterRefresh(context, applicationArguments);\nstopWatch.stop();\nif (this.logStartupInfo) {\nnew StartupInfoLogger(this.mainApplicationClass)\n.logStarted(getApplicationLog(), stopWatch);\n}\n\/** 8.\u53d1\u5e03\u5e94\u7528\u5df2\u7ecf\u542f\u52a8\u4e8b\u4ef6 *\/\nlisteners.started(context);\ncallRunners(context, applicationArguments);\n}\ncatch (Throwable ex) {\nhandleRunFailure(context, ex, exceptionReporters, listeners);\nthrow new IllegalStateException(ex);\n}\n\ntry {\n\/** 9.\u53d1\u5e03\u5e94\u7528\u5df2\u7ecf\u542f\u52a8\u5b8c\u6210\u7684\u76d1\u542c\u4e8b\u4ef6 *\/\nlisteners.running(context);\n}\ncatch (Throwable ex) {\nhandleRunFailure(context, ex, exceptionReporters, null);\nthrow new IllegalStateException(ex);\n}\nreturn context;\n}<\/code><\/pre>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029305\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029306\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4ee3\u7801\u4e2d\u4e3b\u8981\u5c31\u662f\u901a\u8fc7 switch \u8bed\u53e5\uff0c\u6839\u636e webApplicationType \u7684\u7c7b\u578b\u6765\u521b\u5efa\u4e0d\u540c\u7684 ApplicationContext\uff1a<\/p>\n<ul>\n<li>DEFAULT_SERVLET_WEB_CONTEXT_CLASS\uff1aWeb \u7c7b\u578b\uff0c\u5b9e\u4f8b\u5316 AnnotationConfigServletWebServerApplicationContext<\/li>\n<li>DEFAULT_REACTIVE_WEB_CONTEXT_CLASS\uff1a\u54cd\u5e94\u5f0f Web \u7c7b\u578b\uff0c\u5b9e\u4f8b\u5316 AnnotationConfigReactiveWebServerApplicationContext<\/li>\n<li>DEFAULT_CONTEXT_CLASS\uff1a\u975e Web \u7c7b\u578b\uff0c\u5b9e\u4f8b\u5316 AnnotationConfigApplicationContext<\/li>\n<\/ul>\n<h4>2.4 \u521b\u5efa\u5b8c\u5e94\u7528\u4e0a\u4e0b\u6587\u4e4b\u540e\uff0c\u6211\u4eec\u5728\u770b\u5237\u65b0\u4e0a\u4e0b\u6587\u65b9\u6cd5<\/h4>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029307\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e00\u6b65\u6b65\u901a\u8fc7\u65ad\u70b9\u70b9\u51fb\u65b9\u6cd5\u8fdb\u53bb\u67e5\u770b\uff0c\u6211\u4eec\u770b\u5230\u5f88\u719f\u6089\u4ee3\u7801 spring \u7684\u76f8\u5173\u4ee3\u7801\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029308\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<pre><code>@Override\npublic void refresh() throws BeansException, IllegalStateException {\nsynchronized (this.startupShutdownMonitor) {\n\/\/ Prepare this context for refreshing.\n\/\/\u521d\u59cb\u5316\u524d\u7684\u51c6\u5907\u5de5\u4f5c\uff0c\u4e3b\u8981\u662f\u4e00\u4e9b\u7cfb\u7edf\u5c5e\u6027\u3001\u73af\u5883\u53d8\u91cf\u7684\u6821\u9a8c\uff0c\u6bd4\u5982Spring\u542f\u52a8\u9700\u8981\u67d0\u4e9b\u73af\u5883\u53d8\u91cf\uff0c\u53ef\u4ee5\u5728\u8fd9\u4e2a\u5730\u65b9\u8fdb\u884c\u8bbe\u7f6e\u548c\u6821\u9a8c\nprepareRefresh();\n\n\/\/ Tell the subclass to refresh the internal bean factory.\nConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();\n\n\/\/ Prepare the bean factory for use in this context.\n\/\/\u51c6\u5907bean\u5de5\u5382 \u6ce8\u518c\u4e86\u90e8\u5206\u7c7b\nprepareBeanFactory(beanFactory);\n\ntry {\n\/\/ Allows post-processing of the bean factory in context subclasses.\npostProcessBeanFactory(beanFactory);\n\n\/\/ Invoke factory processors registered as beans in the context.\n\/\/\u6ce8\u518cbean\u5de5\u5382\u540e\u7f6e\u5904\u7406\u5668\uff0c\u5e76\u89e3\u6790java\u4ee3\u7801\u914d\u7f6ebean\u5b9a\u4e49\ninvokeBeanFactoryPostProcessors(beanFactory);\n\n\/\/ Register bean processors that intercept bean creation.\n\/\/\u6ce8\u518cbean\u540e\u7f6e\u5904\u7406\u5668\uff0c\u5e76\u4e0d\u4f1a\u6267\u884c\u540e\u7f6e\u5904\u7406\u5668\uff0c\u5728\u540e\u9762\u5b9e\u4f8b\u5316\u7684\u65f6\u5019\u6267\u884c\nregisterBeanPostProcessors(beanFactory);\n\n\/\/ Initialize message source for this context.\ninitMessageSource();\n\n\/\/ Initialize event multicaster for this context.\n\/\/\u521d\u59cb\u5316\u4e8b\u4ef6\u76d1\u542c\u591a\u8def\u5e7f\u64ad\u5668\ninitApplicationEventMulticaster();\n\n\/\/ Initialize other special beans in specific context subclasses.\n\/\/\u5f85\u5b50\u7c7b\u5b9e\u73b0\uff0cspringBoot\u5728\u8fd9\u91cc\u5b9e\u73b0\u521b\u5efa\u5185\u7f6e\u7684tomact\u5bb9\u5668\nonRefresh();\n\n\/\/ Check for listener beans and register them.\nregisterListeners();\n\n\/\/ Instantiate all remaining (non-lazy-init) singletons.\nfinishBeanFactoryInitialization(beanFactory);\n\n\/\/ Last step: publish corresponding event.\nfinishRefresh();\n}\n\ncatch (BeansException ex) {\nif (logger.isWarnEnabled()) {\nlogger.warn(&quot;Exception encountered during context initialization - &quot; +\n&quot;cancelling refresh attempt: &quot; + ex);\n}\n\n\/\/ Destroy already created singletons to avoid dangling resources.\ndestroyBeans();\n\n\/\/ Reset 'active' flag.\ncancelRefresh(ex);\n\n\/\/ Propagate exception to caller.\nthrow ex;\n}\n\nfinally {\n\/\/ Reset common introspection caches in Spring's core, since we\n\/\/ might not ever need metadata for singleton beans anymore...\nresetCommonCaches();\n}\n}\n}<\/code><\/pre>\n<h4>2.5 onRefresh () \u65b9\u6cd5\u662f\u8c03\u7528\u5176\u5b50\u7c7b\u5b9e\u73b0\u7684<\/h4>\n<p>\u4e5f\u5c31\u662f ServletWebServerApplicationContext<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029309\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029310\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<pre><code>\/** \u5f97\u5230Servlet\u5de5\u5382 **\/\nthis.webServer = factory.getWebServer(getSelfInitializer());<\/code><\/pre>\n<p>\u5176\u4e2d createWebServer () \u65b9\u6cd5\u662f\u7528\u6765\u542f\u52a8 web \u670d\u52a1\u7684\uff0c\u4f46\u662f\u8fd8\u6ca1\u6709\u771f\u6b63\u542f\u52a8 Tomcat\uff0c\u53ea\u662f\u901a\u8fc7 ServletWebServerFactory \u521b\u5efa\u4e86\u4e00\u4e2a WebServer\uff0c\u7ee7\u7eed\u6765\u770b\u8fd9\u4e2a ServletWebServerFactory\uff1a<\/p>\n<p>this.webServer = factory.getWebServer (getSelfInitializer ()); \u8fd9\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u770b\u51fa TomcatServletWebServerFactory \u7684\u5b9e\u73b0\u3002\u76f8\u5173 Tomcat \u7684\u5b9e\u73b0\u3002<\/p>\n<h4>2.6 TomcatServletWebServerFactory \u7684 getWebServer () \u65b9\u6cd5<\/h4>\n<p>\u6e05\u6670\u7684\u770b\u5230 new \u51fa\u6765\u4e86\u4e00\u4e2a Tomcat.<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029311\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h4>2.7 Tomcat \u521b\u5efa\u4e4b\u540e\uff0c\u7ee7\u7eed\u5206\u6790 Tomcat \u7684\u76f8\u5173\u8bbe\u7f6e\u548c\u53c2\u6570<\/h4>\n<pre><code>@Override\npublic WebServer getWebServer(ServletContextInitializer... initializers) {\n\n\/** 1\u3001\u521b\u5efaTomcat\u5b9e\u4f8b **\/\nTomcat tomcat = new Tomcat();\n\/\/\u521b\u5efaTomcat\u5de5\u4f5c\u76ee\u5f55\nFile baseDir = (this.baseDirectory != null) ? this.baseDirectory\n: createTempDir(&quot;tomcat&quot;);\ntomcat.setBaseDir(baseDir.getAbsolutePath());\nConnector connector = new Connector(this.protocol);\ntomcat.getService().addConnector(connector);\ncustomizeConnector(connector);\n\/** 2\u3001\u7ed9\u521b\u5efa\u597d\u7684tomcat\u8bbe\u7f6e\u8fde\u63a5\u5668connector **\/\ntomcat.setConnector(connector);\n\/** 3.\u8bbe\u7f6e\u4e0d\u81ea\u52a8\u90e8\u7f72 **\/\ntomcat.getHost().setAutoDeploy(false);\n\/** 4.\u914d\u7f6eTomcat\u5bb9\u5668\u5f15\u64ce **\/\nconfigureEngine(tomcat.getEngine());\nfor (Connector additionalConnector : this.additionalTomcatConnectors) {\ntomcat.getService().addConnector(additionalConnector);\n}\n\/**\u51c6\u5907Tomcat\u7684StandardContext\uff0c\u5e76\u6dfb\u52a0\u5230Tomcat\u4e2d*\/\nprepareContext(tomcat.getHost(), initializers);\n\/** \u5c06\u521b\u5efa\u597d\u7684Tomcat\u5305\u88c5\u6210WebServer\u8fd4\u56de**\/\nreturn getTomcatWebServer(tomcat);\n}<\/code><\/pre>\n<h4>2.8 \u7ee7\u7eed\u70b9\u51fb getTomcatWebServer \u65b9\u6cd5\uff0c\u627e\u5230 initialize () \u65b9\u6cd5\uff0c\u53ef\u4ee5\u770b\u5230 tomcat.start (); \u542f\u52a8 tomcat \u670d\u52a1\u65b9\u6cd5\u3002<\/h4>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029312\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029313\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<pre><code>\/\/ Start the server to trigger initialization listeners\n\/\/\u542f\u52a8tomcat\u670d\u52a1\nthis.tomcat.start();\n\/\/\u5f00\u542f\u963b\u585e\u975e\u5b88\u62a4\u8fdb\u7a0b\nstartDaemonAwaitThread();<\/code><\/pre>\n<p>\/\/Tomcat.java<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029314\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029315\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h4>2.9 TomcatWebServer.java \u63a7\u5236\u53f0\u4f1a\u6253\u5370\u8fd9\u53e5\u8bdd<\/h4>\n<p>Tomcat started on port(s): 8080 (http) with context path \u2018\u2019<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029316\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029317\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>3 \u603b\u7ed3<\/h3>\n<p>SpringBoot \u7684\u542f\u52a8\u4e3b\u8981\u662f\u901a\u8fc7\u5b9e\u4f8b\u5316 SpringApplication \u6765\u542f\u52a8\u7684\uff0c\u542f\u52a8\u8fc7\u7a0b\u4e3b\u8981\u505a\u4e86\u5982\u4e0b\u51e0\u4ef6\u4e8b\u60c5\uff1a<\/p>\n<p>\u914d\u7f6e\u7cfb\u7edf\u5c5e\u6027\u3001\u83b7\u53d6\u76d1\u542c\u5668\uff0c\u53d1\u5e03\u5e94\u7528\u5f00\u59cb\u542f\u52a8\u4e8b\u4ef6\u3001\u521d\u59cb\u5316\u53c2\u6570\u3001\u914d\u7f6e\u73af\u5883\u3001\u521b\u5efa\u5e94\u7528\u4e0a\u4e0b\u6587\u3001\u9884\u5904\u7406\u4e0a\u4e0b\u6587\u3001\u5237\u65b0\u4e0a\u4e0b\u6587\u3001\u518d\u6b21\u5237\u65b0\u4e0a\u4e0b\u6587\u3001\u53d1\u5e03\u5e94\u7528\u5df2\u7ecf\u542f\u52a8\u4e8b\u4ef6\u3001\u53d1\u5e03\u5e94\u7528\u542f\u52a8\u5b8c\u6210\u4e8b\u4ef6\u3002\u800c\u542f\u52a8 Tomcat \u662f\u5237\u65b0\u4e0a\u4e0b\u6587 \u8fd9\u4e00\u6b65\u3002<\/p>\n<p>Spring Boot \u521b\u5efa Tomcat \u65f6\uff0c\u4f1a\u5148\u521b\u5efa\u4e00\u4e2a\u4e0a\u4e0b\u6587\uff0c\u5c06 WebApplicationContext \u4f20\u7ed9 Tomcat\uff1b<\/p>\n<p>\u542f\u52a8 Web \u5bb9\u5668\uff0c\u9700\u8981\u8c03\u7528 getWebserver ()\uff0c\u56e0\u4e3a\u9ed8\u8ba4\u7684 Web \u73af\u5883\u5c31\u662f TomcatServletWebServerFactory\uff0c\u6240\u4ee5\u4f1a\u521b\u5efa Tomcat \u7684 Webserver\uff0c\u8fd9\u91cc\u4f1a\u628a\u6839\u4e0a\u4e0b\u6587\u4f5c\u4e3a\u53c2\u6570\u7ed9 TomcatServletWebServerFactory \u7684 getWebServer ()\uff1b\u542f\u52a8 Tomcat\uff0c\u8c03\u7528 Tomcat \u4e2d Host\u3001Engine \u7684\u542f\u52a8\u65b9\u6cd5\u3002<\/p>\n<h4>3.1 Tomcat \u76f8\u5173\u540d\u79f0\u4ecb\u7ecd<\/h4>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043029318\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043029301\">https:\/\/segmentfault.com\/a\/1190000043029301<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1a\u674e\u5ca9\u79d1 1 \u80cc\u666f SpringBoot \u662f\u4e00\u4e2a\u6846\u67b6\uff0c\u4e00\u79cd\u5168\u65b0\u7684\u7f16\u7a0b\u89c4\u8303\uff0c\u4ed6\u7684\u4ea7\u751f\u7b80\u5316\u4e86\u6846\u67b6\u7684\u4f7f\u7528\uff0c\u540c\u65f6\u4e5f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10006972","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006972","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006972"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006972\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}