You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/09/20 02:11:08 UTC

[incubator-servicecomb-java-chassis] 02/08: SCB-910 add pom for support spring boot 2

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit e8aab8a42343999421baa48464e04852f6d279af
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Fri Sep 14 09:03:01 2018 +0800

    SCB-910 add pom for support spring boot 2
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 java-chassis-dependencies-springboot2/pom.xml      | 157 +++++++++++++++++++++
 pom.xml                                            |   2 +
 spring-boot2-starter-parent/pom.xml                |  57 ++++++++
 .../spring-boot2-starter-servlet/pom.xml           |  51 +++++++
 .../starter/servlet/RestServletInitializer.java    |  73 ++++++++++
 .../springboot2/starter/servlet/package-info.java  |  18 +++
 6 files changed, 358 insertions(+)

diff --git a/java-chassis-dependencies-springboot2/pom.xml b/java-chassis-dependencies-springboot2/pom.xml
new file mode 100644
index 0000000..a5800df
--- /dev/null
+++ b/java-chassis-dependencies-springboot2/pom.xml
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>java-chassis</artifactId>
+    <groupId>org.apache.servicecomb</groupId>
+    <version>1.1.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>java-chassis-dependencies-springboot2</artifactId>
+
+  <name>Java Chassis::Dependencies::SpringBoot2</name>
+  <packaging>pom</packaging>
+
+  <properties>
+    <spring.version>5.0.4.RELEASE</spring.version>
+    <spring.boot.version>2.0.0.RELEASE</spring.boot.version>
+    <spring.data.version>2.0.5.RELEASE</spring.data.version>
+    <spring.session.version>2.0.3.RELEASE</spring.session.version>
+  </properties>
+
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter</artifactId>
+        <version>${spring.boot.version}</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-web</artifactId>
+        <version>${spring.boot.version}</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+
+      <dependency>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-context</artifactId>
+        <version>${spring.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-web</artifactId>
+        <version>${spring.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-webmvc</artifactId>
+        <version>${spring.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-aop</artifactId>
+        <version>${spring.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-aspects</artifactId>
+        <version>${spring.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-beans</artifactId>
+        <version>${spring.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-core</artifactId>
+        <version>${spring.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-expression</artifactId>
+        <version>${spring.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-jdbc</artifactId>
+        <version>${spring.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-orm</artifactId>
+        <version>${spring.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-oxm</artifactId>
+        <version>${spring.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework</groupId>
+        <artifactId>spring-tx</artifactId>
+        <version>${spring.version}</version>
+      </dependency>
+
+      <dependency>
+        <groupId>org.springframework.data</groupId>
+        <artifactId>spring-data-jpa</artifactId>
+        <version>${spring.data.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework.data</groupId>
+        <artifactId>spring-data-commons</artifactId>
+        <version>${spring.data.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework.data</groupId>
+        <artifactId>spring-data-keyvalue</artifactId>
+        <version>${spring.data.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework.data</groupId>
+        <artifactId>spring-data-redis</artifactId>
+        <version>${spring.data.version}</version>
+      </dependency>
+
+      <dependency>
+        <groupId>org.springframework.session</groupId>
+        <artifactId>spring-session-data-redis</artifactId>
+        <version>${spring.session.version}</version>
+      </dependency>
+
+      <dependency>
+        <groupId>org.apache.servicecomb</groupId>
+        <artifactId>java-chassis-dependencies</artifactId>
+        <version>1.1.0-SNAPSHOT</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+
+    </dependencies>
+  </dependencyManagement>
+
+</project>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index adc0bbf..d161bd4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -107,6 +107,8 @@
     <module>metrics</module>
     <module>dynamic-config</module>
     <module>archetypes</module>
+    <module>java-chassis-dependencies-springboot2</module>
+    <module>spring-boot2-starter-parent</module>
   </modules>
 
   <build>
diff --git a/spring-boot2-starter-parent/pom.xml b/spring-boot2-starter-parent/pom.xml
new file mode 100644
index 0000000..9f82e1a
--- /dev/null
+++ b/spring-boot2-starter-parent/pom.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <groupId>org.apache.servicecomb</groupId>
+    <artifactId>java-chassis-dependencies-springboot2</artifactId>
+    <version>1.1.0-SNAPSHOT</version>
+    <relativePath>../java-chassis-dependencies-springboot2</relativePath>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>spring-boot2-starter-parent</artifactId>
+  <packaging>pom</packaging>
+  <version>1.1.0-SNAPSHOT</version>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <java.version>1.8</java.version>
+    <argLine>-Dfile.encoding=UTF-8</argLine>
+  </properties>
+
+  <modules>
+    <module>spring-boot2-starter-servlet</module>
+  </modules>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.8</source>
+          <target>1.8</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
\ No newline at end of file
diff --git a/spring-boot2-starter-parent/spring-boot2-starter-servlet/pom.xml b/spring-boot2-starter-parent/spring-boot2-starter-servlet/pom.xml
new file mode 100644
index 0000000..58f1c7d
--- /dev/null
+++ b/spring-boot2-starter-parent/spring-boot2-starter-servlet/pom.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>spring-boot2-starter-parent</artifactId>
+    <groupId>org.apache.servicecomb</groupId>
+    <version>1.1.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>spring-boot2-starter-servlet</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>spring-boot-starter-servicecomb</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>transport-rest-servlet</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>javax.servlet-api</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicecomb</groupId>
+      <artifactId>foundation-test-scaffolding</artifactId>
+    </dependency>
+  </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/spring-boot2-starter-parent/spring-boot2-starter-servlet/src/main/java/org/apache/servicecomb/springboot2/starter/servlet/RestServletInitializer.java b/spring-boot2-starter-parent/spring-boot2-starter-servlet/src/main/java/org/apache/servicecomb/springboot2/starter/servlet/RestServletInitializer.java
new file mode 100644
index 0000000..0852816
--- /dev/null
+++ b/spring-boot2-starter-parent/spring-boot2-starter-servlet/src/main/java/org/apache/servicecomb/springboot2/starter/servlet/RestServletInitializer.java
@@ -0,0 +1,73 @@
+/*
+ * 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.servicecomb.springboot2.starter.servlet;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.servicecomb.transport.rest.servlet.ServletConfig;
+import org.apache.servicecomb.transport.rest.servlet.ServletUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.web.server.AbstractConfigurableWebServerFactory;
+import org.springframework.boot.web.server.WebServerFactoryCustomizer;
+import org.springframework.boot.web.servlet.ServletContextInitializer;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import com.netflix.config.DynamicPropertyFactory;
+
+@Component
+public class RestServletInitializer
+    implements WebServerFactoryCustomizer<AbstractConfigurableWebServerFactory>, ServletContextInitializer {
+  private static final Logger LOGGER = LoggerFactory.getLogger(RestServletInitializer.class);
+
+  private AbstractConfigurableWebServerFactory factory;
+
+  @Override
+  public void customize(AbstractConfigurableWebServerFactory factory) {
+    this.factory = factory;
+  }
+
+  @Override
+  public void onStartup(ServletContext servletContext) throws ServletException {
+    if (factory.getPort() == 0) {
+      LOGGER.warn(
+          "spring boot embed web container listen port is 0, serviceComb will not use container's port to handler RESTful request.");
+      return;
+    }
+
+    // web container did not did listen now.
+    // so mock to listen, and then close.
+    try (ServerSocket ss = new ServerSocket(factory.getPort(), 0, factory.getAddress())) {
+      if (StringUtils.isEmpty(ServletConfig.getServletUrlPattern())) {
+        // ensure the servlet will be instantiated
+        Configuration configuration = (Configuration) DynamicPropertyFactory.getBackingConfigurationSource();
+        configuration.setProperty(ServletConfig.KEY_SERVLET_URL_PATTERN, ServletConfig.DEFAULT_URL_PATTERN);
+      }
+
+      ServletUtils.init(servletContext);
+    } catch (IOException e) {
+      throw new ServletException(e);
+    }
+  }
+}
\ No newline at end of file
diff --git a/spring-boot2-starter-parent/spring-boot2-starter-servlet/src/main/java/org/apache/servicecomb/springboot2/starter/servlet/package-info.java b/spring-boot2-starter-parent/spring-boot2-starter-servlet/src/main/java/org/apache/servicecomb/springboot2/starter/servlet/package-info.java
new file mode 100644
index 0000000..0413028
--- /dev/null
+++ b/spring-boot2-starter-parent/spring-boot2-starter-servlet/src/main/java/org/apache/servicecomb/springboot2/starter/servlet/package-info.java
@@ -0,0 +1,18 @@
+/*
+ * 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.servicecomb.springboot2.starter.servlet;
\ No newline at end of file