您可以使用将战争文件添加到嵌入式Tomcat
Tomcat.addWebapp。正如其javadoc所说,它是“相当于将Web应用程序添加到Tomcat的Web应用程序目录中”。要在Spring
Boot中使用此API,您需要使用一个自定义
TomcatEmbeddedServletContainerFactory子类:
@Beanpublic EmbeddedServletContainerFactory servletContainerFactory() { return new TomcatEmbeddedServletContainerFactory() { @Override protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer( Tomcat tomcat) { // Ensure that the webapps directory exists new File(tomcat.getServer().getCatalinabase(), "webapps").mkdirs(); try { Context context = tomcat.addWebapp("/foo", "/path/to/foo.war"); // Allow the webapp to load classes from your fat jar context.setParentClassLoader(getClass().getClassLoader()); } catch (ServletException ex) { throw new IllegalStateException("Failed to add webapp", ex); } return super.getTomcatEmbeddedServletContainer(tomcat); } };}

![如何将war文件部署到独立安装在Spring Boot应用程序的内置Tomcat服务器中?[重复] 如何将war文件部署到独立安装在Spring Boot应用程序的内置Tomcat服务器中?[重复]](http://www.mshxw.com/aiimages/31/615568.png)
