From 8f843642dc02cc428b7f466836ca67e5bda20527 Mon Sep 17 00:00:00 2001 From: qibaoguang Date: Fri, 17 Apr 2015 00:29:13 +0800 Subject: [PATCH] Update 74.5. Deploying a WAR in an Old (Servlet 2.5) Container.md --- ...ing a WAR in an Old (Servlet 2.5) Container.md | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/IX. ‘How-to’ guides/74.5. Deploying a WAR in an Old (Servlet 2.5) Container.md b/IX. ‘How-to’ guides/74.5. Deploying a WAR in an Old (Servlet 2.5) Container.md index e69de29..d190bdb 100644 --- a/IX. ‘How-to’ guides/74.5. Deploying a WAR in an Old (Servlet 2.5) Container.md +++ b/IX. ‘How-to’ guides/74.5. Deploying a WAR in an Old (Servlet 2.5) Container.md @@ -0,0 +1,46 @@ +### 74.5. 部署WAR到老的(Servlet2.5)容器 + +Spring Boot使用 Servlet 3.0 APIs初始化ServletContext(注册Servlets等),所以你不能在一个Servlet 2.5的容器中原封不动的使用同样的应用。使用一些特定的工具也是可以在一个老的容器中运行Spring Boot应用的。如果添加了`org.springframework.boot:spring-boot-legacy`依赖,你只需要创建一个web.xml,声明一个用于创建应用上下文的上下文监听器,过滤器和servlets。上下文监听器是专用于Spring Boot的,其他的都是一个Servlet 2.5的Spring应用所具有的。示例: +```xml + + + + + contextConfigLocation + demo.Application + + + + org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener + + + + metricFilter + org.springframework.web.filter.DelegatingFilterProxy + + + + metricFilter + /* + + + + appServlet + org.springframework.web.servlet.DispatcherServlet + + contextAttribute + org.springframework.web.context.WebApplicationContext.ROOT + + 1 + + + + appServlet + / + + + +``` +在该示例中,我们使用一个单一的应用上下文(通过上下文监听器创建的),然后使用一个init参数将它附加到DispatcherServlet。这在一个Spring Boot应用中是很正常的(你通常只有一个应用上下文)。