{"id":4551,"date":"2019-11-09T09:08:44","date_gmt":"2019-11-09T01:08:44","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=4551"},"modified":"2019-11-09T09:08:44","modified_gmt":"2019-11-09T01:08:44","slug":"%e4%bf%ae%e5%a4%8d-org-springframework-context-applicationcontextexception-unable-to-start-embedded-container-%e6%8a%a5%e9%94%99%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4551","title":{"rendered":"\u4fee\u590d org.springframework.context.ApplicationContextException: Unable to start embedded container \u62a5\u9519\u95ee\u9898"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">SpringBoot \u7684\u8fd9\u4e2a\u9519\u8bef\u5f88\u5e38\u89c1\uff0c\u4e5f\u5f88\u7b80\u5355\uff0c\u4f46\u4e5f\u8db3\u4ee5\u62b5\u6321\u4f4f\u4e0d\u5c11\u65b0\u624b\u5b66\u4e60\u8005\uff0c\u8ba9\u4ed6\u4eec\u4e3e\u6b65\u7ef4\u8270\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u8fd1\u6709\u4e00\u4e2a\u7f51\u53cb\u5c31\u79c1\u4fe1\u6211\u8bf4\uff0c\u4ed6\u7684 SpringBoot \u7a0b\u5e8f\u65e0\u6cd5\u542f\u52a8\uff0c\u62a5 org.springframework.context.ApplicationContextException: Unable to start embedded container \u5f02\u5e38\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6839\u636e\u8fd9\u4e2a\u5f02\u5e38\u5f97\u77e5\uff0c\u662f SpringBoot \u5185\u5d4c\u7684\u5bb9\u5668\u65e0\u6cd5\u542f\u52a8\u4e86\u3002\u81f3\u4e8e\u5177\u4f53\u7684\u539f\u56e0\u8fd8\u5f97\u770b\u8be6\u7ec6\u65e5\u5fd7\u4e86\u3002\u4e00\u756a\u6c9f\u901a\u540e\uff0c\u4ed6\u628a\u9519\u8bef\u65e5\u5fd7\u53d1\u7ed9\u4e86\u6211\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>2019-11-09 08:49:59  [ main:28882 ] - [ ERROR ]  Application startup failed\norg.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.IllegalArgumentException: Error page location [xttblog\/404.jsp] must start with a '\/'\n\tat org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)\n\tat org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)\n\tat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)\n\tat org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:303)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)\n\tat com.xttblog.MainApplication.main(MainApplication.java:60)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:67)\nCaused by: java.lang.IllegalArgumentException: Error page location [xttblog\/404.jsp] must start with a '\/'\n\tat org.apache.catalina.core.StandardContext.addErrorPage(StandardContext.java:2930)\n\tat org.springframework.boot.context.embedded.tomcat.TomcatErrorPage.addToContext(TomcatErrorPage.java:83)\n\tat org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.configureContext(TomcatEmbeddedServletContainerFactory.java:491)\n\tat org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.prepareContext(TomcatEmbeddedServletContainerFactory.java:235)\n\tat org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:178)\n\tat org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164)\n\tat org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6839\u636e\u8fd9\u4e2a\u9519\u8bef\u65e5\u5fd7\uff0c\u6211\u4e00\u773c\u5c31\u770b\u51fa\u4e86\u539f\u56e0\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b80\u5355\u6765\u8bf4\uff0c\u5c31\u662f\u4ed6\u4f7f\u7528\u4e86 org.springframework.boot.web.servlet.ErrorPage \u5b9a\u4e49\u4e86 404 \u7684\u9875\u9762\uff0c\u8ba9\u7a0b\u5e8f\u51fa\u73b0 404 \u540e\uff0c\u8df3\u8f6c\u5230\u81ea\u5df1\u5b9a\u4e49\u7684 404 \u9875\u9762\u4e0a\uff0c\u800c\u4e0d\u662f\u4f7f\u7528 nginx \u6216 tomcat\u3001SpringBoot \u7b49\u9ed8\u8ba4\u7684 404 \u9875\u9762\u4e0a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531\u4e8e Spring Boot \u9ed8\u8ba4\u4f7f\u7528\u5d4c\u5165\u5f0f Tomcat \u5bb9\u5668\uff0c\u9ed8\u8ba4\u6ca1\u6709\u9875\u9762\u6765\u5904\u7406 404 \u7b49\u5e38\u89c1\u9519\u8bef\u3002\u56e0\u6b64\uff0c\u4e3a\u4e86\u7ed9\u7528\u6237\u6700\u4f73\u7684\u4f7f\u7528\u4f53\u9a8c\uff0c404 \u7b49\u5e38\u89c1\u9519\u8bef\u9700\u8981\u6211\u4eec\u81ea\u5b9a\u4e49\u9875\u9762\u6765\u5904\u7406\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u65f6\uff0cSpringboot \u63d0\u4f9b\u7684 ErrorPage \u8fd9\u4e2a\u7c7b\u7684\u4f5c\u7528\u5c31\u53ef\u4ee5\u6d3e\u4e0a\u7528\u573a\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Bean\npublic EmbeddedServletContainerCustomizer containerCustomizer() {\n    return new EmbeddedServletContainerCustomizer() {\n        @Override\n        public void customize(ConfigurableEmbeddedServletContainer container) {\n\n            ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, \"\/403.html\");\n            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, \"xttblog\/404.jsp\");\n            ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, \"\/500.html\");\n\n            container.addErrorPages(error401Page, error404Page, error500Page);\n        }\n    };\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f ErrorPage \u7684 path \u53c2\u6570\uff0c\u5fc5\u987b\u662f\u4ee5\u201c\/\u201d\u5f00\u5934\u7684\u8def\u5f84\u5b57\u7b26\u4e32\u3002\u5982\u679c\u4e0d\u662f\u4ee5\u201c\/\u201d\u5f00\u5934\u7684\u5c31\u4f1a\u62a5\u672c\u6587\u6240\u8bf4\u7684\u8fd9\u4e2a\u5f02\u5e38\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ErrorPage \u975e\u5e38\u7684\u5f3a\u5927\uff0c\u8fd8\u53ef\u4ee5\u5b9a\u4e49\u6839\u636e\u5f02\u5e38\u6765\u9009\u62e9\u5c55\u793a\u7684\u9875\u9762\u3002\u7528\u597d\u5b83\uff0c\u4e5f\u53ef\u4ee5\u7ed9\u7528\u6237\u5e26\u6765\u4e0d\u5c11\u53cb\u597d\u7684\u4f53\u9a8c\u611f\uff01<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4551\">\u4fee\u590d org.springframework.context.ApplicationContextException: Unable to start embedded container \u62a5\u9519\u95ee\u9898<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>SpringBoot \u7684\u8fd9\u4e2a\u9519\u8bef\u5f88\u5e38\u89c1\uff0c\u4e5f\u5f88\u7b80\u5355\uff0c\u4f46\u4e5f\u8db3\u4ee5\u62b5\u6321\u4f4f\u4e0d\u5c11\u65b0\u624b\u5b66\u4e60\u8005\uff0c\u8ba9\u4ed6\u4eec\u4e3e\u6b65\u7ef4\u8270\u3002 \u6700\u8fd1\u6709\u4e00\u4e2a\u7f51 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[266,1522,414,946,785],"class_list":["post-4551","post","type-post","status-publish","format-standard","hentry","category-java","tag-java","tag-springboot","tag-spring","tag-946","tag-785"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4551"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4551\/revisions"}],"predecessor-version":[{"id":4552,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4551\/revisions\/4552"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}