diff --git a/cse-spring-boot-starter-provider/src/main/java/io/servicecomb/springboot/starter/provider/CseSpringApplicationRunListener.java b/cse-spring-boot-starter-provider/src/main/java/io/servicecomb/springboot/starter/provider/CseSpringApplicationRunListener.java deleted file mode 100644 index f522304516a..00000000000 --- a/cse-spring-boot-starter-provider/src/main/java/io/servicecomb/springboot/starter/provider/CseSpringApplicationRunListener.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd - * - * Licensed 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 io.servicecomb.springboot.starter.provider; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.SpringApplicationRunListener; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.env.ConfigurableEnvironment; - -import io.servicecomb.foundation.common.utils.BeanUtils; -import io.servicecomb.foundation.common.utils.Log4jUtils; - -/** - * <一句话功能简述> - * <功能详细描述> - * - * @version [版本号, 2017年4月17日] - * @see [相关类/方法] - * @since [产品/模块版本] - */ -public class CseSpringApplicationRunListener implements SpringApplicationRunListener { - private static final Logger LOGGER = LoggerFactory.getLogger(CseSpringApplicationRunListener.class); - - public CseSpringApplicationRunListener(SpringApplication app, String[] args) { - } - - /** - * {@inheritDoc} - */ - @Override - public void started() { - try { - Log4jUtils.init(); - } catch (Exception e) { - throw new Error(e); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void environmentPrepared(ConfigurableEnvironment environment) { - - } - - /** - * {@inheritDoc} - */ - @Override - public void contextPrepared(ConfigurableApplicationContext context) { - - } - - /** - * {@inheritDoc} - */ - @Override - public void contextLoaded(ConfigurableApplicationContext context) { - // 引入了spring cloud context的场景中会实例化多个springApplication,需要规避一下 - if (context.getParent() != null) { - return; - } - - LOGGER.info("Initializing the CSE..."); - - try { - XmlBeanDefinitionReader beanDefinitionReader = - new XmlBeanDefinitionReader((BeanDefinitionRegistry) context.getBeanFactory()); - beanDefinitionReader.loadBeanDefinitions(BeanUtils.DEFAULT_BEAN_RESOURCE); - } catch (Throwable e) { - LOGGER.error("Error to initialize CSE...", e); - - throw new Error(e); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void finished(ConfigurableApplicationContext context, Throwable exception) { - - } - -} diff --git a/cse-spring-boot-starter-provider/src/main/java/io/servicecomb/springboot/starter/provider/EnableServiceComb.java b/cse-spring-boot-starter-provider/src/main/java/io/servicecomb/springboot/starter/provider/EnableServiceComb.java new file mode 100644 index 00000000000..abc3dd4483f --- /dev/null +++ b/cse-spring-boot-starter-provider/src/main/java/io/servicecomb/springboot/starter/provider/EnableServiceComb.java @@ -0,0 +1,32 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd + * + * Licensed 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 io.servicecomb.springboot.starter.provider; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.springframework.context.annotation.Import; + +/** + * This annotation enables auto-configuration of Spring beans to integrate with ServiceComb modules. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Import(ServiceCombSpringConfiguration.class) +public @interface EnableServiceComb { + +} diff --git a/cse-spring-boot-starter-provider/src/main/java/io/servicecomb/springboot/starter/provider/ServiceCombSpringConfiguration.java b/cse-spring-boot-starter-provider/src/main/java/io/servicecomb/springboot/starter/provider/ServiceCombSpringConfiguration.java new file mode 100644 index 00000000000..7697069d7fd --- /dev/null +++ b/cse-spring-boot-starter-provider/src/main/java/io/servicecomb/springboot/starter/provider/ServiceCombSpringConfiguration.java @@ -0,0 +1,25 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd + * + * Licensed 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 io.servicecomb.springboot.starter.provider; + +import io.servicecomb.foundation.common.utils.BeanUtils; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; + +@Configuration +@ImportResource(BeanUtils.DEFAULT_BEAN_RESOURCE) +class ServiceCombSpringConfiguration { +} diff --git a/cse-spring-boot-starter-provider/src/main/resources/META-INF/spring.factories b/cse-spring-boot-starter-provider/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 64fb41d9ff2..00000000000 --- a/cse-spring-boot-starter-provider/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1 +0,0 @@ -org.springframework.boot.SpringApplicationRunListener=io.servicecomb.springboot.starter.provider.CseSpringApplicationRunListener \ No newline at end of file diff --git a/demo/demo-spring-boot/demo-spring-boot-jaxrs-client/src/main/java/io/servicecomb/springboot/jaxrs/client/JaxrsClient.java b/demo/demo-spring-boot/demo-spring-boot-jaxrs-client/src/main/java/io/servicecomb/springboot/jaxrs/client/JaxrsClient.java index de0bebe3738..c6f152caea3 100644 --- a/demo/demo-spring-boot/demo-spring-boot-jaxrs-client/src/main/java/io/servicecomb/springboot/jaxrs/client/JaxrsClient.java +++ b/demo/demo-spring-boot/demo-spring-boot-jaxrs-client/src/main/java/io/servicecomb/springboot/jaxrs/client/JaxrsClient.java @@ -16,6 +16,7 @@ package io.servicecomb.springboot.jaxrs.client; +import io.servicecomb.springboot.starter.provider.EnableServiceComb; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -25,6 +26,7 @@ * */ @SpringBootApplication +@EnableServiceComb public class JaxrsClient { public static void main(String[] args) throws Exception { diff --git a/demo/demo-spring-boot/demo-spring-boot-jaxrs-server/src/main/java/io/servicecomb/springboot/jaxrs/server/JaxrsServer.java b/demo/demo-spring-boot/demo-spring-boot-jaxrs-server/src/main/java/io/servicecomb/springboot/jaxrs/server/JaxrsServer.java index 87debf9af72..a2450300ccd 100644 --- a/demo/demo-spring-boot/demo-spring-boot-jaxrs-server/src/main/java/io/servicecomb/springboot/jaxrs/server/JaxrsServer.java +++ b/demo/demo-spring-boot/demo-spring-boot-jaxrs-server/src/main/java/io/servicecomb/springboot/jaxrs/server/JaxrsServer.java @@ -16,6 +16,7 @@ package io.servicecomb.springboot.jaxrs.server; +import io.servicecomb.springboot.starter.provider.EnableServiceComb; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -25,6 +26,7 @@ * */ @SpringBootApplication +@EnableServiceComb public class JaxrsServer { /** *