diff --git a/sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/runtime/SofaRuntimeAutoConfiguration.java b/sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/runtime/SofaRuntimeAutoConfiguration.java index bd65a0b3b..6ff7e86c7 100644 --- a/sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/runtime/SofaRuntimeAutoConfiguration.java +++ b/sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/runtime/SofaRuntimeAutoConfiguration.java @@ -19,7 +19,6 @@ import com.alipay.sofa.boot.autoconfigure.condition.ConditionalOnSwitch; import com.alipay.sofa.boot.constant.SofaBootConstants; import com.alipay.sofa.boot.log.SofaBootLoggerFactory; -import com.alipay.sofa.boot.util.ServiceLoaderUtils; import com.alipay.sofa.common.thread.NamedThreadFactory; import com.alipay.sofa.common.thread.SofaThreadPoolExecutor; import com.alipay.sofa.runtime.api.client.ReferenceClient; @@ -57,8 +56,10 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.util.Assert; +import java.util.HashSet; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -116,8 +117,8 @@ public static SofaRuntimeContext sofaRuntimeContext(SofaRuntimeManager sofaRunti @ConditionalOnMissingBean public static BindingConverterFactory bindingConverterFactory() { BindingConverterFactory bindingConverterFactory = new BindingConverterFactoryImpl(); - bindingConverterFactory.addBindingConverters(ServiceLoaderUtils - .getClassesByServiceLoader(BindingConverter.class)); + bindingConverterFactory.addBindingConverters(new HashSet<>(SpringFactoriesLoader + .loadFactories(BindingConverter.class, null))); return bindingConverterFactory; } @@ -125,8 +126,8 @@ public static BindingConverterFactory bindingConverterFactory() { @ConditionalOnMissingBean public static BindingAdapterFactory bindingAdapterFactory() { BindingAdapterFactory bindingAdapterFactory = new BindingAdapterFactoryImpl(); - bindingAdapterFactory.addBindingAdapters(ServiceLoaderUtils - .getClassesByServiceLoader(BindingAdapter.class)); + bindingAdapterFactory.addBindingAdapters(new HashSet<>(SpringFactoriesLoader.loadFactories( + BindingAdapter.class, null))); return bindingAdapterFactory; } diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport deleted file mode 100644 index e557c094d..000000000 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport +++ /dev/null @@ -1 +0,0 @@ -com.alipay.sofa.rpc.boot.runtime.parser.GlobalFilterParser diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.runtime.spi.binding.BindingAdapter b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.runtime.spi.binding.BindingAdapter deleted file mode 100644 index b95c8ce35..000000000 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.runtime.spi.binding.BindingAdapter +++ /dev/null @@ -1,6 +0,0 @@ -com.alipay.sofa.rpc.boot.runtime.adapter.BoltBindingAdapter -com.alipay.sofa.rpc.boot.runtime.adapter.RestBindingAdapter -com.alipay.sofa.rpc.boot.runtime.adapter.DubboBindingAdapter -com.alipay.sofa.rpc.boot.runtime.adapter.H2cBindingAdapter -com.alipay.sofa.rpc.boot.runtime.adapter.HttpBindingAdapter -com.alipay.sofa.rpc.boot.runtime.adapter.TripleBindingAdapter \ No newline at end of file diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.runtime.spi.service.BindingConverter b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.runtime.spi.service.BindingConverter deleted file mode 100644 index d8a3a28c1..000000000 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.runtime.spi.service.BindingConverter +++ /dev/null @@ -1,6 +0,0 @@ -com.alipay.sofa.rpc.boot.runtime.converter.BoltBindingConverter -com.alipay.sofa.rpc.boot.runtime.converter.RestBindingConverter -com.alipay.sofa.rpc.boot.runtime.converter.DubboBindingConverter -com.alipay.sofa.rpc.boot.runtime.converter.H2cBindingConverter -com.alipay.sofa.rpc.boot.runtime.converter.HttpBindingConverter -com.alipay.sofa.rpc.boot.runtime.converter.TripleBindingConverter \ No newline at end of file diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/resources/META-INF/spring.factories b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/resources/META-INF/spring.factories index 884fa7ba3..073edaaba 100644 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/resources/META-INF/spring.factories +++ b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/resources/META-INF/spring.factories @@ -1,2 +1,22 @@ org.springframework.context.ApplicationListener=\ - com.alipay.sofa.rpc.boot.context.RpcEnvironmentApplicationListener \ No newline at end of file + com.alipay.sofa.rpc.boot.context.RpcEnvironmentApplicationListener + +com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport=\ + com.alipay.sofa.rpc.boot.runtime.parser.GlobalFilterParser + +com.alipay.sofa.runtime.spi.binding.BindingAdapter=\ + com.alipay.sofa.rpc.boot.runtime.adapter.BoltBindingAdapter,\ + com.alipay.sofa.rpc.boot.runtime.adapter.RestBindingAdapter,\ + com.alipay.sofa.rpc.boot.runtime.adapter.DubboBindingAdapter,\ + com.alipay.sofa.rpc.boot.runtime.adapter.H2cBindingAdapter,\ + com.alipay.sofa.rpc.boot.runtime.adapter.HttpBindingAdapter,\ + com.alipay.sofa.rpc.boot.runtime.adapter.TripleBindingAdapter + +com.alipay.sofa.runtime.spi.service.BindingConverter=\ + com.alipay.sofa.rpc.boot.runtime.converter.BoltBindingConverter,\ + com.alipay.sofa.rpc.boot.runtime.converter.RestBindingConverter,\ + com.alipay.sofa.rpc.boot.runtime.converter.DubboBindingConverter,\ + com.alipay.sofa.rpc.boot.runtime.converter.H2cBindingConverter,\ + com.alipay.sofa.rpc.boot.runtime.converter.HttpBindingConverter,\ + com.alipay.sofa.rpc.boot.runtime.converter.TripleBindingConverter + diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/adapter/BindingAdapterFactoryTests.java b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/adapter/BindingAdapterFactoryTests.java index 85bd7d74a..f29ac87e1 100644 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/adapter/BindingAdapterFactoryTests.java +++ b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/adapter/BindingAdapterFactoryTests.java @@ -16,10 +16,12 @@ */ package com.alipay.sofa.rpc.boot.test.adapter; -import com.alipay.sofa.boot.util.ServiceLoaderUtils; import com.alipay.sofa.runtime.service.impl.BindingAdapterFactoryImpl; import com.alipay.sofa.runtime.spi.binding.BindingAdapter; import org.junit.jupiter.api.Test; +import org.springframework.core.io.support.SpringFactoriesLoader; + +import java.util.HashSet; import static org.assertj.core.api.Assertions.assertThat; @@ -34,8 +36,8 @@ public class BindingAdapterFactoryTests { @Test public void checkOrder() { BindingAdapterFactoryImpl bindingAdapterFactory = new BindingAdapterFactoryImpl(); - bindingAdapterFactory.addBindingAdapters(ServiceLoaderUtils - .getClassesByServiceLoader(BindingAdapter.class)); + bindingAdapterFactory.addBindingAdapters(new HashSet<>(SpringFactoriesLoader.loadFactories( + BindingAdapter.class, null))); BindingAdapter bindingAdapter = bindingAdapterFactory.getBindingAdapter(XBindingAdapter.X); assertThat(bindingAdapter).isInstanceOf(XBindingAdapter2.class); } diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/converter/RpcBindingConverterTests.java b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/converter/RpcBindingConverterTests.java index 72882ced0..1afc2bb6c 100644 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/converter/RpcBindingConverterTests.java +++ b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/converter/RpcBindingConverterTests.java @@ -16,7 +16,6 @@ */ package com.alipay.sofa.rpc.boot.test.converter; -import com.alipay.sofa.boot.util.ServiceLoaderUtils; import com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingMethodInfo; import com.alipay.sofa.rpc.boot.runtime.converter.BoltBindingConverter; import com.alipay.sofa.rpc.boot.runtime.converter.RpcBindingConverter; @@ -27,7 +26,9 @@ import com.alipay.sofa.runtime.spi.service.BindingConverter; import com.alipay.sofa.runtime.spi.service.BindingConverterFactory; import org.junit.jupiter.api.Test; +import org.springframework.core.io.support.SpringFactoriesLoader; +import java.util.HashSet; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -73,8 +74,8 @@ public void parseSofaMethods() { @Test public void checkOrder() { BindingConverterFactory factory = new BindingConverterFactoryImpl(); - factory.addBindingConverters(ServiceLoaderUtils - .getClassesByServiceLoader(BindingConverter.class)); + factory.addBindingConverters(new HashSet<>(SpringFactoriesLoader.loadFactories( + BindingConverter.class, null))); BindingConverter bindingConverter = factory.getBindingConverter(TestBindingConverter.TEST); BindingConverter bindingConverterByTagName = factory .getBindingConverterByTagName(TestBindingConverter.TARGET_NAME); diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/META-INF/services/com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/META-INF/services/com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport deleted file mode 100644 index e557c094d..000000000 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/META-INF/services/com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport +++ /dev/null @@ -1 +0,0 @@ -com.alipay.sofa.rpc.boot.runtime.parser.GlobalFilterParser diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/META-INF/services/com.alipay.sofa.runtime.spi.binding.BindingAdapter b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/META-INF/services/com.alipay.sofa.runtime.spi.binding.BindingAdapter deleted file mode 100644 index 0a0490e9c..000000000 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/META-INF/services/com.alipay.sofa.runtime.spi.binding.BindingAdapter +++ /dev/null @@ -1,9 +0,0 @@ -com.alipay.sofa.rpc.boot.runtime.adapter.BoltBindingAdapter -com.alipay.sofa.rpc.boot.runtime.adapter.RestBindingAdapter -com.alipay.sofa.rpc.boot.runtime.adapter.DubboBindingAdapter -com.alipay.sofa.rpc.boot.runtime.adapter.H2cBindingAdapter -com.alipay.sofa.rpc.boot.runtime.adapter.HttpBindingAdapter -com.alipay.sofa.rpc.boot.test.adapter.XBindingAdapter -com.alipay.sofa.rpc.boot.test.adapter.XBindingAdapter2 -com.alipay.sofa.rpc.boot.test.adapter.XBindingAdapter3 -com.alipay.sofa.rpc.boot.runtime.adapter.TripleBindingAdapter \ No newline at end of file diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/META-INF/services/com.alipay.sofa.runtime.spi.service.BindingConverter b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/META-INF/services/com.alipay.sofa.runtime.spi.service.BindingConverter deleted file mode 100644 index 433cd9b2f..000000000 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/META-INF/services/com.alipay.sofa.runtime.spi.service.BindingConverter +++ /dev/null @@ -1,9 +0,0 @@ -com.alipay.sofa.rpc.boot.runtime.converter.BoltBindingConverter -com.alipay.sofa.rpc.boot.runtime.converter.RestBindingConverter -com.alipay.sofa.rpc.boot.runtime.converter.DubboBindingConverter -com.alipay.sofa.rpc.boot.runtime.converter.H2cBindingConverter -com.alipay.sofa.rpc.boot.runtime.converter.HttpBindingConverter -com.alipay.sofa.rpc.boot.runtime.converter.TripleBindingConverter -com.alipay.sofa.rpc.boot.test.converter.TestBindingConverter -com.alipay.sofa.rpc.boot.test.converter.TestBindingConverter2 -com.alipay.sofa.rpc.boot.test.converter.TestBindingConverter3 diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/META-INF/spring.factories b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/META-INF/spring.factories new file mode 100644 index 000000000..aac691865 --- /dev/null +++ b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/META-INF/spring.factories @@ -0,0 +1,24 @@ +com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport=\ + com.alipay.sofa.rpc.boot.runtime.parser.GlobalFilterParser + +com.alipay.sofa.runtime.spi.binding.BindingAdapter=\ + com.alipay.sofa.rpc.boot.runtime.adapter.BoltBindingAdapter,\ + com.alipay.sofa.rpc.boot.runtime.adapter.RestBindingAdapter,\ + com.alipay.sofa.rpc.boot.runtime.adapter.DubboBindingAdapter,\ + com.alipay.sofa.rpc.boot.runtime.adapter.H2cBindingAdapter,\ + com.alipay.sofa.rpc.boot.runtime.adapter.HttpBindingAdapter,\ + com.alipay.sofa.rpc.boot.runtime.adapter.TripleBindingAdapter,\ + com.alipay.sofa.rpc.boot.test.adapter.XBindingAdapter,\ + com.alipay.sofa.rpc.boot.test.adapter.XBindingAdapter2,\ + com.alipay.sofa.rpc.boot.test.adapter.XBindingAdapter3 + +com.alipay.sofa.runtime.spi.service.BindingConverter=\ + com.alipay.sofa.rpc.boot.runtime.converter.BoltBindingConverter,\ + com.alipay.sofa.rpc.boot.runtime.converter.RestBindingConverter,\ + com.alipay.sofa.rpc.boot.runtime.converter.DubboBindingConverter,\ + com.alipay.sofa.rpc.boot.runtime.converter.H2cBindingConverter,\ + com.alipay.sofa.rpc.boot.runtime.converter.HttpBindingConverter,\ + com.alipay.sofa.rpc.boot.runtime.converter.TripleBindingConverter,\ + com.alipay.sofa.rpc.boot.test.converter.TestBindingConverter,\ + com.alipay.sofa.rpc.boot.test.converter.TestBindingConverter2,\ + com.alipay.sofa.rpc.boot.test.converter.TestBindingConverter3 \ No newline at end of file diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport deleted file mode 100644 index fcb9bb2a4..000000000 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport +++ /dev/null @@ -1,41 +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. -# - -# -# /* -# * 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. -# */ -# - -com.alipay.sofa.runtime.spring.parser.ReferenceDefinitionParser -com.alipay.sofa.runtime.spring.parser.ServiceDefinitionParser -com.alipay.sofa.runtime.spring.parser.AsyncInitBeanDefinitionDecorator -com.alipay.sofa.runtime.ext.spring.parser.ExtensionPointBeanDefinitionParser -com.alipay.sofa.runtime.ext.spring.parser.ExtensionBeanDefinitionParser \ No newline at end of file diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.runtime.spi.binding.BindingAdapter b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.runtime.spi.binding.BindingAdapter deleted file mode 100644 index 65e631535..000000000 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.runtime.spi.binding.BindingAdapter +++ /dev/null @@ -1 +0,0 @@ -com.alipay.sofa.runtime.service.binding.JvmBindingAdapter \ No newline at end of file diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.runtime.spi.service.BindingConverter b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.runtime.spi.service.BindingConverter deleted file mode 100644 index 5cc029210..000000000 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/resources/META-INF/services/com.alipay.sofa.runtime.spi.service.BindingConverter +++ /dev/null @@ -1 +0,0 @@ -com.alipay.sofa.runtime.service.binding.JvmBindingConverter \ No newline at end of file diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/resources/META-INF/spring.factories b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/resources/META-INF/spring.factories index 0cfb393ab..71b2c296a 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/resources/META-INF/spring.factories +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/resources/META-INF/spring.factories @@ -1,3 +1,16 @@ # Initializers com.alipay.sofa.boot.startup.BeanStatCustomizer=\ - com.alipay.sofa.runtime.startup.ComponentBeanStatCustomizer \ No newline at end of file + com.alipay.sofa.runtime.startup.ComponentBeanStatCustomizer + +com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport=\ + com.alipay.sofa.runtime.spring.parser.ReferenceDefinitionParser,\ + com.alipay.sofa.runtime.spring.parser.ServiceDefinitionParser,\ + com.alipay.sofa.runtime.spring.parser.AsyncInitBeanDefinitionDecorator,\ + com.alipay.sofa.runtime.ext.spring.parser.ExtensionPointBeanDefinitionParser,\ + com.alipay.sofa.runtime.ext.spring.parser.ExtensionBeanDefinitionParser + +com.alipay.sofa.runtime.spi.binding.BindingAdapter=\ + com.alipay.sofa.runtime.service.binding.JvmBindingAdapter + +com.alipay.sofa.runtime.spi.service.BindingConverter=\ + com.alipay.sofa.runtime.service.binding.JvmBindingConverter \ No newline at end of file diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/spring/SofaRuntimeManagerTestBase.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/spring/SofaRuntimeManagerTestBase.java index bba5ac256..92eeaee98 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/spring/SofaRuntimeManagerTestBase.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/spring/SofaRuntimeManagerTestBase.java @@ -16,7 +16,6 @@ */ package com.alipay.sofa.runtime.spring; -import com.alipay.sofa.boot.util.ServiceLoaderUtils; import com.alipay.sofa.runtime.api.client.ReferenceClient; import com.alipay.sofa.runtime.api.client.ServiceClient; import com.alipay.sofa.runtime.impl.ClientFactoryImpl; @@ -34,6 +33,9 @@ import com.alipay.sofa.runtime.spi.service.BindingConverter; import com.alipay.sofa.runtime.spi.service.BindingConverterFactory; import org.junit.jupiter.api.BeforeEach; +import org.springframework.core.io.support.SpringFactoriesLoader; + +import java.util.HashSet; /** * @author huzijie @@ -57,11 +59,11 @@ public abstract class SofaRuntimeManagerTestBase { public void init() { clientFactoryInternal = new ClientFactoryImpl(); bindingConverterFactory = new BindingConverterFactoryImpl(); - bindingConverterFactory.addBindingConverters(ServiceLoaderUtils - .getClassesByServiceLoader(BindingConverter.class)); + bindingConverterFactory.addBindingConverters(new HashSet<>(SpringFactoriesLoader + .loadFactories(BindingConverter.class, null))); bindingAdapterFactory = new BindingAdapterFactoryImpl(); - bindingAdapterFactory.addBindingAdapters(ServiceLoaderUtils - .getClassesByServiceLoader(BindingAdapter.class)); + bindingAdapterFactory.addBindingAdapters(new HashSet<>(SpringFactoriesLoader.loadFactories( + BindingAdapter.class, null))); sofaRuntimeManager = new StandardSofaRuntimeManager("testApp", Thread.currentThread() .getContextClassLoader(), clientFactoryInternal); clientFactoryInternal.registerClient(ReferenceClient.class, new ReferenceClientImpl( diff --git a/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/spring/namespace/handler/SofaBootNamespaceHandler.java b/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/spring/namespace/handler/SofaBootNamespaceHandler.java index 1b477ea06..e8dde865d 100644 --- a/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/spring/namespace/handler/SofaBootNamespaceHandler.java +++ b/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/spring/namespace/handler/SofaBootNamespaceHandler.java @@ -22,8 +22,9 @@ import org.springframework.beans.factory.xml.BeanDefinitionDecorator; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.NamespaceHandlerSupport; +import org.springframework.core.io.support.SpringFactoriesLoader; -import java.util.ServiceLoader; +import java.util.List; /** * Implementation of {@link NamespaceHandlerSupport} to register {@link SofaBootTagNameSupport}. @@ -39,8 +40,8 @@ public class SofaBootNamespaceHandler extends NamespaceHandlerSupport { @Override public void init() { - ServiceLoader serviceLoaderSofaBoot = ServiceLoader.load(SofaBootTagNameSupport.class); - serviceLoaderSofaBoot.forEach(this::registerTagParser); + List sofaBootTagNameSupports = SpringFactoriesLoader.loadFactories(SofaBootTagNameSupport.class, null); + sofaBootTagNameSupports.forEach(this::registerTagParser); } private void registerTagParser(SofaBootTagNameSupport tagNameSupport) { diff --git a/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ServiceLoaderUtils.java b/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ServiceLoaderUtils.java deleted file mode 100644 index 56c3e3b1c..000000000 --- a/sofa-boot-project/sofa-boot/src/main/java/com/alipay/sofa/boot/util/ServiceLoaderUtils.java +++ /dev/null @@ -1,45 +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 com.alipay.sofa.boot.util; - -import java.util.HashSet; -import java.util.ServiceLoader; -import java.util.Set; - -/** - * Utility methods that are useful for handle {@link ServiceLoader}. - * - * @author huzijie - * @version ServiceLoaderUtils.java, v 0.1 2023年01月17日 12:20 PM huzijie Exp $ - */ -public class ServiceLoaderUtils { - - /** - * Found all available class form ServiceLoader - * @param clazz class type - * @return all available class - */ - public static Set getClassesByServiceLoader(Class clazz) { - ServiceLoader serviceLoader = ServiceLoader.load(clazz); - - Set result = new HashSet<>(); - for (T t : serviceLoader) { - result.add(t); - } - return result; - } -} diff --git a/sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/ServiceLoaderUtilsTests.java b/sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/ServiceLoaderUtilsTests.java deleted file mode 100644 index fc96aa601..000000000 --- a/sofa-boot-project/sofa-boot/src/test/java/com/alipay/sofa/boot/util/ServiceLoaderUtilsTests.java +++ /dev/null @@ -1,40 +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 com.alipay.sofa.boot.util; - -import com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport; -import org.junit.jupiter.api.Test; - -import java.util.Set; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link ServiceLoaderUtils}. - * - * @author huzijie - * @version ServiceLoaderUtilsTests.java, v 0.1 2023年04月03日 5:39 PM huzijie Exp $ - */ -public class ServiceLoaderUtilsTests { - - @Test - public void getClassesByServiceLoader() { - Set objects = ServiceLoaderUtils - .getClassesByServiceLoader(SofaBootTagNameSupport.class); - assertThat(objects.size()).isEqualTo(3); - } -} diff --git a/sofa-boot-project/sofa-boot/src/test/resources/META-INF/services/com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport b/sofa-boot-project/sofa-boot/src/test/resources/META-INF/services/com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport deleted file mode 100644 index 03d615e09..000000000 --- a/sofa-boot-project/sofa-boot/src/test/resources/META-INF/services/com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport +++ /dev/null @@ -1,3 +0,0 @@ -com.alipay.sofa.boot.spring.namespace.TestBeanDefinitionDecorator -com.alipay.sofa.boot.spring.namespace.TestBeanDefinitionParser -com.alipay.sofa.boot.spring.namespace.TestNormalBean \ No newline at end of file diff --git a/sofa-boot-project/sofa-boot/src/test/resources/META-INF/spring.factories b/sofa-boot-project/sofa-boot/src/test/resources/META-INF/spring.factories new file mode 100644 index 000000000..3fba321f2 --- /dev/null +++ b/sofa-boot-project/sofa-boot/src/test/resources/META-INF/spring.factories @@ -0,0 +1,4 @@ +com.alipay.sofa.boot.spring.namespace.spi.SofaBootTagNameSupport=\ + com.alipay.sofa.boot.spring.namespace.TestBeanDefinitionDecorator,\ + com.alipay.sofa.boot.spring.namespace.TestBeanDefinitionParser,\ + com.alipay.sofa.boot.spring.namespace.TestNormalBean \ No newline at end of file