From 8917ecf30306955578e51e8197c2245a6a1c80bc Mon Sep 17 00:00:00 2001 From: Huxing Zhang Date: Tue, 24 Jul 2018 16:18:53 +0800 Subject: [PATCH 1/6] Ensure compatibility for elegant shutdown under servlet container. #1998 --- .../DubboContextLoaderListener.java | 58 +++++++++++++++++++ .../DubboWebApplicationInitializer.java | 19 ++++++ 2 files changed, 77 insertions(+) create mode 100644 dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java new file mode 100644 index 00000000000..ed5a29ed565 --- /dev/null +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java @@ -0,0 +1,58 @@ +package org.apache.dubbo.config.spring.initializer; + +import org.springframework.web.context.ContextLoaderListener; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.XmlWebApplicationContext; + +import javax.servlet.ServletContext; + +/** + * This class is introduced mainly for compatibility. + * Consider the following case: + * 1. listener class {@link ContextLoaderListener} is defined in web.xml + * servlet container will initialized {@link ContextLoaderListener} before this class. + * Therefore Dubbo's elegant shutdown feature will not be enabled. + * To enable it, you need to either: + * 1) remove listener class {@link ContextLoaderListener} in your web.xml + * 2) change listener class to {@link DubboContextLoaderListener} in your web.xml + * 2. listener class {@link DubboContextLoaderListener} is defined in web.xml + * This is automatically enable Dubbo's elegant shutdown feature, + * even for a servlet container which is not 3.0 compatible + * 3. no listener class defined in web.xml + * Dubbo's elegant shutdown feature will be automatically enabled + * if Dubbo is running under a servlet 3.0+ compatible container + * see {@link DubboWebApplicationInitializer} for more details. + */ +public class DubboContextLoaderListener extends ContextLoaderListener { + + /** + * The root WebApplicationContext instance that this loader manages. + */ + private WebApplicationContext context; + + /** + * This is used for xml configuration, which does not require servlet version to be 3.0+ + */ + public DubboContextLoaderListener(){ + super(); + this.context = new XmlWebApplicationContext(); + ((XmlWebApplicationContext)context).addApplicationListener(new DubboApplicationListener()); + } + + /** + * This is used for programmatic API, which requires servlet version to be 3.0+ + * @param context the web application context + */ + public DubboContextLoaderListener(WebApplicationContext context) { + this.context = context; + } + + @Override + public WebApplicationContext initWebApplicationContext(ServletContext servletContext) { + if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) { + // if the root web application has already been created, just ignore. + return this.context; + } + return super.initWebApplicationContext(servletContext); + } +} diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboWebApplicationInitializer.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboWebApplicationInitializer.java index 582535bb8bf..bed92a5f261 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboWebApplicationInitializer.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboWebApplicationInitializer.java @@ -20,6 +20,8 @@ import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.XmlWebApplicationContext; +import javax.servlet.ServletContext; + /** * An initializer to register {@link DubboApplicationListener} * to the ApplicationContext seamlessly. @@ -37,4 +39,21 @@ protected WebApplicationContext createRootApplicationContext() { webApplicationContext.addApplicationListener(new DubboApplicationListener()); return webApplicationContext; } + + /** + * Register {@link DubboContextLoaderListener} to application context. + * @param servletContext + */ + protected void registerContextLoaderListener(ServletContext servletContext) { + WebApplicationContext rootAppContext = createRootApplicationContext(); + if (rootAppContext != null) { + DubboContextLoaderListener listener = new DubboContextLoaderListener(rootAppContext); + listener.setContextInitializers(getRootApplicationContextInitializers()); + servletContext.addListener(listener); + } + else { + logger.debug("No ContextLoaderListener registered, as " + + "createRootApplicationContext() did not return an application context"); + } + } } From 5bc0cc690abf72a9587d08b9549f8e7855347de3 Mon Sep 17 00:00:00 2001 From: Huxing Zhang Date: Tue, 24 Jul 2018 16:25:24 +0800 Subject: [PATCH 2/6] No need to call super() because it does nothing. --- .../config/spring/initializer/DubboContextLoaderListener.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java index ed5a29ed565..c674e180029 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java @@ -34,7 +34,6 @@ public class DubboContextLoaderListener extends ContextLoaderListener { * This is used for xml configuration, which does not require servlet version to be 3.0+ */ public DubboContextLoaderListener(){ - super(); this.context = new XmlWebApplicationContext(); ((XmlWebApplicationContext)context).addApplicationListener(new DubboApplicationListener()); } From 6fb1cab066a3f73787420ce0eb4508423e9edc23 Mon Sep 17 00:00:00 2001 From: Huxing Zhang Date: Wed, 25 Jul 2018 09:50:06 +0800 Subject: [PATCH 3/6] Add ASF header. --- .../initializer/DubboContextLoaderListener.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java index c674e180029..4a071b5e93a 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.dubbo.config.spring.initializer; import org.springframework.web.context.ContextLoaderListener; From 35d3b1620e4feabcd5cac66ce6d1619758c4b45d Mon Sep 17 00:00:00 2001 From: Huxing Zhang Date: Wed, 25 Jul 2018 13:32:33 +0800 Subject: [PATCH 4/6] Simplify DubboApplicationListener auto discovery by using web-fragment.xml. --- dubbo-config/dubbo-config-spring/pom.xml | 7 +- .../DubboApplicationContextInitializer.java | 39 ++++++++++ .../DubboContextLoaderListener.java | 73 ------------------- .../DubboWebApplicationInitializer.java | 59 --------------- .../main/resources/META-INF/web-fragment.xml | 22 ++++++ 5 files changed, 66 insertions(+), 134 deletions(-) create mode 100644 dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboApplicationContextInitializer.java delete mode 100644 dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java delete mode 100644 dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboWebApplicationInitializer.java create mode 100644 dubbo-config/dubbo-config-spring/src/main/resources/META-INF/web-fragment.xml diff --git a/dubbo-config/dubbo-config-spring/pom.xml b/dubbo-config/dubbo-config-spring/pom.xml index dc333e7a8e4..995209db45e 100644 --- a/dubbo-config/dubbo-config-spring/pom.xml +++ b/dubbo-config/dubbo-config-spring/pom.xml @@ -112,18 +112,21 @@ javax.el test - org.springframework spring-tx test - org.springframework spring-test test + + org.apache.tomcat.embed + tomcat-embed-core + test + diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboApplicationContextInitializer.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboApplicationContextInitializer.java new file mode 100644 index 00000000000..36727e669f4 --- /dev/null +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboApplicationContextInitializer.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.config.spring.initializer; + +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; + +/** + * Automatically register {@link DubboApplicationListener} to Spring context + * A {@link org.springframework.web.context.ContextLoaderListener} class is defined in + * src/main/resources/META-INF/web-fragment.xml + * In the web-fragment.xml, {@link DubboApplicationContextInitializer} is defined in context params. + * This file will be discovered if running under a servlet 3.0+ container. + * Even if user specifies {@link org.springframework.web.context.ContextLoaderListener} in web.xml, + * it will be merged to web.xml. + * If user specifies in web.xml, this will no take effect, + * unless user configures {@link DubboApplicationContextInitializer} explicitly in web.xml. + */ +public class DubboApplicationContextInitializer implements ApplicationContextInitializer { + + @Override + public void initialize(ConfigurableApplicationContext applicationContext) { + applicationContext.addApplicationListener(new DubboApplicationListener()); + } +} diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java deleted file mode 100644 index 4a071b5e93a..00000000000 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboContextLoaderListener.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.config.spring.initializer; - -import org.springframework.web.context.ContextLoaderListener; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.XmlWebApplicationContext; - -import javax.servlet.ServletContext; - -/** - * This class is introduced mainly for compatibility. - * Consider the following case: - * 1. listener class {@link ContextLoaderListener} is defined in web.xml - * servlet container will initialized {@link ContextLoaderListener} before this class. - * Therefore Dubbo's elegant shutdown feature will not be enabled. - * To enable it, you need to either: - * 1) remove listener class {@link ContextLoaderListener} in your web.xml - * 2) change listener class to {@link DubboContextLoaderListener} in your web.xml - * 2. listener class {@link DubboContextLoaderListener} is defined in web.xml - * This is automatically enable Dubbo's elegant shutdown feature, - * even for a servlet container which is not 3.0 compatible - * 3. no listener class defined in web.xml - * Dubbo's elegant shutdown feature will be automatically enabled - * if Dubbo is running under a servlet 3.0+ compatible container - * see {@link DubboWebApplicationInitializer} for more details. - */ -public class DubboContextLoaderListener extends ContextLoaderListener { - - /** - * The root WebApplicationContext instance that this loader manages. - */ - private WebApplicationContext context; - - /** - * This is used for xml configuration, which does not require servlet version to be 3.0+ - */ - public DubboContextLoaderListener(){ - this.context = new XmlWebApplicationContext(); - ((XmlWebApplicationContext)context).addApplicationListener(new DubboApplicationListener()); - } - - /** - * This is used for programmatic API, which requires servlet version to be 3.0+ - * @param context the web application context - */ - public DubboContextLoaderListener(WebApplicationContext context) { - this.context = context; - } - - @Override - public WebApplicationContext initWebApplicationContext(ServletContext servletContext) { - if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) { - // if the root web application has already been created, just ignore. - return this.context; - } - return super.initWebApplicationContext(servletContext); - } -} diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboWebApplicationInitializer.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboWebApplicationInitializer.java deleted file mode 100644 index bed92a5f261..00000000000 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/initializer/DubboWebApplicationInitializer.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.config.spring.initializer; - -import org.springframework.web.context.AbstractContextLoaderInitializer; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.XmlWebApplicationContext; - -import javax.servlet.ServletContext; - -/** - * An initializer to register {@link DubboApplicationListener} - * to the ApplicationContext seamlessly. - */ -public class DubboWebApplicationInitializer extends AbstractContextLoaderInitializer { - - /** - * This method won't be triggered if running on spring-boot. - * It only works when running under a servlet container. - * @return a WebApplicationContext with DubboApplicationListener registered. - */ - @Override - protected WebApplicationContext createRootApplicationContext() { - XmlWebApplicationContext webApplicationContext = new XmlWebApplicationContext(); - webApplicationContext.addApplicationListener(new DubboApplicationListener()); - return webApplicationContext; - } - - /** - * Register {@link DubboContextLoaderListener} to application context. - * @param servletContext - */ - protected void registerContextLoaderListener(ServletContext servletContext) { - WebApplicationContext rootAppContext = createRootApplicationContext(); - if (rootAppContext != null) { - DubboContextLoaderListener listener = new DubboContextLoaderListener(rootAppContext); - listener.setContextInitializers(getRootApplicationContextInitializers()); - servletContext.addListener(listener); - } - else { - logger.debug("No ContextLoaderListener registered, as " + - "createRootApplicationContext() did not return an application context"); - } - } -} diff --git a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/web-fragment.xml b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/web-fragment.xml new file mode 100644 index 00000000000..220874ab78c --- /dev/null +++ b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/web-fragment.xml @@ -0,0 +1,22 @@ + + + dubbo-fragment + + + + + + + + + contextInitializerClasses + org.apache.dubbo.config.spring.initializer.DubboApplicationContextInitializer + + + + org.springframework.web.context.ContextLoaderListener + + + \ No newline at end of file From 3ff2d182615fbd6373aeaffe41767decef1e226c Mon Sep 17 00:00:00 2001 From: Huxing Zhang Date: Wed, 25 Jul 2018 13:33:26 +0800 Subject: [PATCH 5/6] Add unit test. --- ...ubboApplicationContextInitializerTest.java | 87 +++++++++++++++++++ .../src/test/resources/applicationContext.xml | 6 ++ .../resources/webapps/test/WEB-INF/web.xml | 14 +++ .../resources/webapps/test2/WEB-INF/web.xml | 10 +++ .../resources/webapps/test3/WEB-INF/web.xml | 10 +++ 5 files changed, 127 insertions(+) create mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/initializer/DubboApplicationContextInitializerTest.java create mode 100644 dubbo-config/dubbo-config-spring/src/test/resources/applicationContext.xml create mode 100644 dubbo-config/dubbo-config-spring/src/test/resources/webapps/test/WEB-INF/web.xml create mode 100644 dubbo-config/dubbo-config-spring/src/test/resources/webapps/test2/WEB-INF/web.xml create mode 100644 dubbo-config/dubbo-config-spring/src/test/resources/webapps/test3/WEB-INF/web.xml diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/initializer/DubboApplicationContextInitializerTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/initializer/DubboApplicationContextInitializerTest.java new file mode 100644 index 00000000000..90a32f67307 --- /dev/null +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/initializer/DubboApplicationContextInitializerTest.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.config.spring.initializer; + +import org.apache.catalina.core.StandardContext; +import org.apache.catalina.startup.ContextConfig; +import org.apache.catalina.startup.Tomcat; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.web.context.ContextLoaderListener; + + +public class DubboApplicationContextInitializerTest { + + @Test + public void testSpringContextLoaderListenerInWebXml() throws Exception { + Tomcat tomcat = new Tomcat(); + tomcat.setBaseDir("src/test/resources"); + tomcat.setPort(12345); + StandardContext context = new StandardContext(); + context.setName("test"); + context.setDocBase("test"); + context.setPath("/test"); + context.addLifecycleListener(new ContextConfig()); + tomcat.getHost().addChild(context); + tomcat.start(); + // there should be two application listeners + Assert.assertEquals(1, context.getApplicationLifecycleListeners().length); + // the first one should be Spring's built in ContextLoaderListener. + Assert.assertTrue(context.getApplicationLifecycleListeners()[0] instanceof ContextLoaderListener); + tomcat.stop(); + tomcat.destroy(); + } + + @Test + public void testNoListenerInWebXml() throws Exception { + Tomcat tomcat = new Tomcat(); + tomcat.setBaseDir("src/test/resources"); + tomcat.setPort(12345); + StandardContext context = new StandardContext(); + context.setName("test2"); + context.setDocBase("test2"); + context.setPath("/test2"); + context.addLifecycleListener(new ContextConfig()); + tomcat.getHost().addChild(context); + tomcat.start(); + // there should be two application listeners + Assert.assertEquals(1, context.getApplicationLifecycleListeners().length); + // the first one should be Spring's built in ContextLoaderListener. + Assert.assertTrue(context.getApplicationLifecycleListeners()[0] instanceof ContextLoaderListener); + tomcat.stop(); + tomcat.destroy(); + } + + @Test + public void testMetadataComplete() throws Exception { + Tomcat tomcat = new Tomcat(); + tomcat.setBaseDir("src/test/resources"); + tomcat.setPort(12345); + StandardContext context = new StandardContext(); + context.setName("test3"); + context.setDocBase("test3"); + context.setPath("/test3"); + context.addLifecycleListener(new ContextConfig()); + tomcat.getHost().addChild(context); + tomcat.start(); + // there should be two application listeners + Assert.assertEquals(0, context.getApplicationLifecycleListeners().length); + tomcat.stop(); + tomcat.destroy(); + } + +} diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/applicationContext.xml b/dubbo-config/dubbo-config-spring/src/test/resources/applicationContext.xml new file mode 100644 index 00000000000..977a8a43d05 --- /dev/null +++ b/dubbo-config/dubbo-config-spring/src/test/resources/applicationContext.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/webapps/test/WEB-INF/web.xml b/dubbo-config/dubbo-config-spring/src/test/resources/webapps/test/WEB-INF/web.xml new file mode 100644 index 00000000000..25214e23e35 --- /dev/null +++ b/dubbo-config/dubbo-config-spring/src/test/resources/webapps/test/WEB-INF/web.xml @@ -0,0 +1,14 @@ + + + dubbo-demo + + + contextConfigLocation + classpath:applicationContext.xml + + + + org.springframework.web.context.ContextLoaderListener + + + diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/webapps/test2/WEB-INF/web.xml b/dubbo-config/dubbo-config-spring/src/test/resources/webapps/test2/WEB-INF/web.xml new file mode 100644 index 00000000000..0da8d8a5db2 --- /dev/null +++ b/dubbo-config/dubbo-config-spring/src/test/resources/webapps/test2/WEB-INF/web.xml @@ -0,0 +1,10 @@ + + + dubbo-demo + + + contextConfigLocation + classpath:applicationContext.xml + + + diff --git a/dubbo-config/dubbo-config-spring/src/test/resources/webapps/test3/WEB-INF/web.xml b/dubbo-config/dubbo-config-spring/src/test/resources/webapps/test3/WEB-INF/web.xml new file mode 100644 index 00000000000..81a5a13f9ed --- /dev/null +++ b/dubbo-config/dubbo-config-spring/src/test/resources/webapps/test3/WEB-INF/web.xml @@ -0,0 +1,10 @@ + + + dubbo-demo + + + contextConfigLocation + classpath:applicationContext.xml + + + From 3cc52c8ce7eef86c93b9d67437f25b622af5c0a7 Mon Sep 17 00:00:00 2001 From: Huxing Zhang Date: Wed, 25 Jul 2018 13:44:29 +0800 Subject: [PATCH 6/6] Polish comments. --- .../initializer/DubboApplicationContextInitializerTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/initializer/DubboApplicationContextInitializerTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/initializer/DubboApplicationContextInitializerTest.java index 90a32f67307..2c84095f4e3 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/initializer/DubboApplicationContextInitializerTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/initializer/DubboApplicationContextInitializerTest.java @@ -38,7 +38,7 @@ public void testSpringContextLoaderListenerInWebXml() throws Exception { context.addLifecycleListener(new ContextConfig()); tomcat.getHost().addChild(context); tomcat.start(); - // there should be two application listeners + // there should be 1 application listener Assert.assertEquals(1, context.getApplicationLifecycleListeners().length); // the first one should be Spring's built in ContextLoaderListener. Assert.assertTrue(context.getApplicationLifecycleListeners()[0] instanceof ContextLoaderListener); @@ -58,7 +58,7 @@ public void testNoListenerInWebXml() throws Exception { context.addLifecycleListener(new ContextConfig()); tomcat.getHost().addChild(context); tomcat.start(); - // there should be two application listeners + // there should be 1 application listener Assert.assertEquals(1, context.getApplicationLifecycleListeners().length); // the first one should be Spring's built in ContextLoaderListener. Assert.assertTrue(context.getApplicationLifecycleListeners()[0] instanceof ContextLoaderListener); @@ -78,7 +78,7 @@ public void testMetadataComplete() throws Exception { context.addLifecycleListener(new ContextConfig()); tomcat.getHost().addChild(context); tomcat.start(); - // there should be two application listeners + // there should be no application listeners Assert.assertEquals(0, context.getApplicationLifecycleListeners().length); tomcat.stop(); tomcat.destroy();