diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java index 5e092d8bb1f..a92df0f712e 100644 --- a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java +++ b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-client/src/main/java/org/apache/servicecomb/springboot/springmvc/client/SpringmvcClient.java @@ -36,7 +36,7 @@ public static void main(final String[] args) throws Exception { new SpringApplicationBuilder().sources(SpringmvcClient.class).web(WebApplicationType.SERVLET).build().run(args); - org.apache.servicecomb.demo.springmvc.client.SpringmvcClient.run(); + org.apache.servicecomb.demo.springmvc.SpringmvcClient.run(); TestMgr.summary(); } diff --git a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java index 311bd535874..1e52dab4c78 100644 --- a/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java +++ b/demo/demo-spring-boot-transport/demo-spring-boot-springmvc-server/src/main/java/org/apache/servicecomb/springboot/springmvc/server/SpringmvcServer.java @@ -23,11 +23,12 @@ import org.slf4j.LoggerFactory; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import com.netflix.config.DynamicPropertyFactory; -@SpringBootApplication +@SpringBootApplication(exclude = {WebMvcAutoConfiguration.class}) @EnableServiceComb public class SpringmvcServer { private static final Logger LOGGER = LoggerFactory.getLogger(SpringmvcServer.class); diff --git a/demo/demo-springmvc/springmvc-client/pom.xml b/demo/demo-springmvc/springmvc-client/pom.xml index a67ddf0c1cc..9abbc43831e 100644 --- a/demo/demo-springmvc/springmvc-client/pom.xml +++ b/demo/demo-springmvc/springmvc-client/pom.xml @@ -61,7 +61,7 @@ - org.apache.servicecomb.demo.springmvc.client.SpringmvcClient + org.apache.servicecomb.demo.springmvc.SpringmvcClient diff --git a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcClient.java similarity index 99% rename from demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java rename to demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcClient.java index 7b37debe36b..2bbd2b61c26 100644 --- a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java +++ b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcClient.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.servicecomb.demo.springmvc.client; +package org.apache.servicecomb.demo.springmvc; import java.util.Date; import java.util.HashMap; @@ -27,6 +27,7 @@ import org.apache.servicecomb.demo.TestMgr; import org.apache.servicecomb.demo.controller.Controller; import org.apache.servicecomb.demo.controller.Person; +import org.apache.servicecomb.demo.springmvc.client.CodeFirstRestTemplateSpringmvc; import org.apache.servicecomb.demo.springmvc.client.ThirdSvc.ThirdSvcClient; import org.apache.servicecomb.foundation.common.utils.BeanUtils; import org.apache.servicecomb.foundation.common.utils.Log4jUtils; diff --git a/demo/demo-springmvc/springmvc-client/src/test/java/org/apache/servicecomb/demo/springmvc/SpringMvcIT.java b/demo/demo-springmvc/springmvc-client/src/test/java/org/apache/servicecomb/demo/springmvc/SpringMvcIT.java index 5d610dee91f..e3f0e4ec05f 100644 --- a/demo/demo-springmvc/springmvc-client/src/test/java/org/apache/servicecomb/demo/springmvc/SpringMvcIT.java +++ b/demo/demo-springmvc/springmvc-client/src/test/java/org/apache/servicecomb/demo/springmvc/SpringMvcIT.java @@ -21,7 +21,6 @@ import static org.junit.Assert.assertThat; import org.apache.servicecomb.demo.TestMgr; -import org.apache.servicecomb.demo.springmvc.client.SpringmvcClient; import org.junit.Before; import org.junit.Test; diff --git a/demo/demo-springmvc/springmvc-server/pom.xml b/demo/demo-springmvc/springmvc-server/pom.xml index 8c4e0e9a96b..9b0f839a10b 100644 --- a/demo/demo-springmvc/springmvc-server/pom.xml +++ b/demo/demo-springmvc/springmvc-server/pom.xml @@ -36,6 +36,10 @@ org.apache.servicecomb provider-springmvc + + + org.apache.servicecomb + provider-pojo org.apache.servicecomb @@ -58,7 +62,7 @@ - org.apache.servicecomb.demo.springmvc.server.SpringmvcServer + org.apache.servicecomb.demo.springmvc.SpringmvcServer diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcServer.java similarity index 95% rename from demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java rename to demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcServer.java index 12af40c09c0..38841a98258 100644 --- a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/SpringmvcServer.java +++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/SpringmvcServer.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.servicecomb.demo.springmvc.server; +package org.apache.servicecomb.demo.springmvc; import org.apache.servicecomb.foundation.common.utils.BeanUtils; import org.apache.servicecomb.foundation.common.utils.Log4jUtils; diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java index e36dcd784c8..16ddd927de4 100644 --- a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java +++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/server/ProducerTestsAfterBootup.java @@ -91,9 +91,9 @@ public void testSchemaNotChange(SCBEngine scbEngine) { public void testRegisteredBasePath() { if (DynamicPropertyFactory.getInstance().getBooleanProperty("servicecomb.test.vert.transport", true).get()) { - TestMgr.check(19, RegistrationManager.INSTANCE.getMicroservice().getPaths().size()); - } else { TestMgr.check(20, RegistrationManager.INSTANCE.getMicroservice().getPaths().size()); + } else { + TestMgr.check(21, RegistrationManager.INSTANCE.getMicroservice().getPaths().size()); } } diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/EarlyConsumer.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/EarlyConsumer.java new file mode 100644 index 00000000000..eb43fe1aeab --- /dev/null +++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/EarlyConsumer.java @@ -0,0 +1,62 @@ +/* + * 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.demo.springmvc.third; + +import org.apache.servicecomb.core.BootListener; +import org.apache.servicecomb.provider.pojo.RpcReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * see: https://github.com/apache/servicecomb-java-chassis/issues/2534 + */ +@Component +public class EarlyConsumer implements BootListener { + private static final Logger LOGGER = LoggerFactory.getLogger(EarlyConsumer.class); + + @RpcReference(microserviceName = "third", schemaId = "heartbeat") + private HealthSchema healthSchema; + + private volatile boolean stopped = false; + + public EarlyConsumer() { + new Thread() { + public void run() { + while (!stopped) { + LOGGER.info("calling service"); + try { + healthSchema.heartbeat(); + } catch (Throwable e) { + // ignore error + } + try { + Thread.sleep(100); + } catch (Throwable e) { + // ignore error + } + } + } + }.start(); + } + + @Override + public void onAfterRegistry(BootEvent event) { + stopped = true; + } +} \ No newline at end of file diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/HealthSchema.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/HealthSchema.java new file mode 100644 index 00000000000..d1f8be2b451 --- /dev/null +++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/HealthSchema.java @@ -0,0 +1,27 @@ +/* + * 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.demo.springmvc.third; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +@RequestMapping("/v1") +public interface HealthSchema { + @GetMapping(value = "/heartbeat") + void heartbeat(); +} \ No newline at end of file diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/HeartBeatService.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/HeartBeatService.java new file mode 100644 index 00000000000..d01b2103343 --- /dev/null +++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/HeartBeatService.java @@ -0,0 +1,28 @@ +/* + * 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.demo.springmvc.third; + +import org.apache.servicecomb.provider.rest.common.RestSchema; + +@RestSchema(schemaId = "health", schemaInterface = HealthSchema.class) +public class HeartBeatService implements HealthSchema { + @Override + public void heartbeat() { + + } +} diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/NormalConsumer.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/NormalConsumer.java new file mode 100644 index 00000000000..72ce2eca908 --- /dev/null +++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/NormalConsumer.java @@ -0,0 +1,56 @@ +/* + * 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.demo.springmvc.third; + +import org.apache.servicecomb.core.BootListener; +import org.apache.servicecomb.demo.TestMgr; +import org.apache.servicecomb.provider.pojo.RpcReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * see: https://github.com/apache/servicecomb-java-chassis/issues/2534 + */ +@Component +public class NormalConsumer implements BootListener { + private static final Logger LOGGER = LoggerFactory.getLogger(NormalConsumer.class); + + @RpcReference(microserviceName = "third", schemaId = "heartbeat") + private HealthSchema healthSchema; + + @Override + public void onAfterRegistry(BootListener.BootEvent event) { + try { + LOGGER.info("calling service after register"); + + healthSchema.heartbeat(); + LOGGER.info("heartbeat succ"); + } catch (Throwable e) { + TestMgr.failed("3rd invoke failed", e); + throw e; + } + } + + + @Override + public int getOrder() { + // 比ThirdServiceRegister晚 + return 0; + } +} \ No newline at end of file diff --git a/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/Register.java b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/Register.java new file mode 100644 index 00000000000..16cb416d7e2 --- /dev/null +++ b/demo/demo-springmvc/springmvc-server/src/main/java/org/apache/servicecomb/demo/springmvc/third/Register.java @@ -0,0 +1,35 @@ +/* + * 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.demo.springmvc.third; + +import java.util.Arrays; + +import org.apache.servicecomb.provider.pojo.registry.ThirdServiceWithInvokerRegister; +import org.springframework.stereotype.Component; + +/** + * see: https://github.com/apache/servicecomb-java-chassis/issues/2534 + */ +@Component +public class Register extends ThirdServiceWithInvokerRegister { + public Register() { + super("third"); + addSchema("heartbeat", HealthSchema.class); + setUrls("", Arrays.asList("rest://localhost:8080?sslEnabled=false")); + } +} \ No newline at end of file