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 2023/02/27 07:55:14 UTC
[servicecomb-java-chassis] branch master updated: [SCB-2785]support spring boot auto configure and remove component scan (#3674)
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/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 76b579b99 [SCB-2785]support spring boot auto configure and remove component scan (#3674)
76b579b99 is described below
commit 76b579b990391825ed50a47c2715f50785b36656
Author: liubao68 <bi...@qq.com>
AuthorDate: Mon Feb 27 15:55:09 2023 +0800
[SCB-2785]support spring boot auto configure and remove component scan (#3674)
---
...java => FoundationCommonAuthConfiguration.java} | 19 ++------
.../servicecomb/foundation/auth/ShaAKSKCipher.java | 3 --
.../src/main/resources/META-INF/spring.factories | 19 ++++++++
.../servicecomb/config/DynamicPropertiesImpl.java | 2 -
.../config/FoundationConfigConfiguration.java | 57 ++++++++++++++++++++++
.../config/LastPropertyPlaceholderConfigurer.java | 2 -
.../config/inject/InjectBeanPostProcessor.java | 2 -
.../config/priority/ConfigObjectFactory.java | 2 -
.../config/priority/PriorityPropertyFactory.java | 2 -
.../config/priority/PriorityPropertyManager.java | 2 -
.../src/main/resources/META-INF/spring.factories | 19 ++++++++
.../transport/highway/HighwayClientFilter.java | 2 -
.../highway/HighwayServerCodecFilter.java | 2 -
.../highway/TransportHighwayConfiguration.java | 24 +++++----
.../src/main/resources/META-INF/spring.factories | 19 ++++++++
15 files changed, 130 insertions(+), 46 deletions(-)
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/auth/ShaAKSKCipher.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/auth/FoundationCommonAuthConfiguration.java
similarity index 73%
copy from foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/auth/ShaAKSKCipher.java
copy to foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/auth/FoundationCommonAuthConfiguration.java
index e7449745e..19ea1e752 100644
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/auth/ShaAKSKCipher.java
+++ b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/auth/FoundationCommonAuthConfiguration.java
@@ -14,22 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.servicecomb.foundation.auth;
-import org.springframework.stereotype.Component;
-
-@Component
-public class ShaAKSKCipher implements Cipher {
- public static final String CIPHER_NAME = "ShaAKSKCipher";
-
- @Override
- public String name() {
- return CIPHER_NAME;
- }
+import org.springframework.context.annotation.Configuration;
- @Override
- public char[] decrypt(char[] encrypted) {
- return encrypted;
+@Configuration
+public class FoundationCommonAuthConfiguration {
+ public ShaAKSKCipher shaAKSKCipher() {
+ return new ShaAKSKCipher();
}
}
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/auth/ShaAKSKCipher.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/auth/ShaAKSKCipher.java
index e7449745e..ee857e644 100644
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/auth/ShaAKSKCipher.java
+++ b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/auth/ShaAKSKCipher.java
@@ -17,9 +17,6 @@
package org.apache.servicecomb.foundation.auth;
-import org.springframework.stereotype.Component;
-
-@Component
public class ShaAKSKCipher implements Cipher {
public static final String CIPHER_NAME = "ShaAKSKCipher";
diff --git a/foundations/foundation-common/src/main/resources/META-INF/spring.factories b/foundations/foundation-common/src/main/resources/META-INF/spring.factories
new file mode 100644
index 000000000..21399bcd6
--- /dev/null
+++ b/foundations/foundation-common/src/main/resources/META-INF/spring.factories
@@ -0,0 +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.
+## ---------------------------------------------------------------------------
+
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+ org.apache.servicecomb.foundation.auth.FoundationCommonAuthConfiguration
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesImpl.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesImpl.java
index c90caa4c7..cb94c655d 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesImpl.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/DynamicPropertiesImpl.java
@@ -24,7 +24,6 @@ import java.util.function.IntConsumer;
import java.util.function.LongConsumer;
import org.apache.commons.configuration.AbstractConfiguration;
-import org.springframework.stereotype.Component;
import com.netflix.config.ConcurrentCompositeConfiguration;
import com.netflix.config.ConfigurationManager;
@@ -36,7 +35,6 @@ import com.netflix.config.DynamicLongProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
-@Component
class DynamicPropertiesImpl implements DynamicProperties {
public DynamicPropertiesImpl() {
}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java
new file mode 100644
index 000000000..e3651b111
--- /dev/null
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/FoundationConfigConfiguration.java
@@ -0,0 +1,57 @@
+/*
+ * 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.config;
+
+import org.apache.servicecomb.config.inject.InjectBeanPostProcessor;
+import org.apache.servicecomb.config.priority.ConfigObjectFactory;
+import org.apache.servicecomb.config.priority.PriorityPropertyFactory;
+import org.apache.servicecomb.config.priority.PriorityPropertyManager;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class FoundationConfigConfiguration {
+ @Bean
+ public InjectBeanPostProcessor injectBeanPostProcessor(PriorityPropertyManager priorityPropertyManager) {
+ return new InjectBeanPostProcessor(priorityPropertyManager);
+ }
+
+ @Bean
+ public PriorityPropertyManager priorityPropertyManager(ConfigObjectFactory configObjectFactory) {
+ return new PriorityPropertyManager(configObjectFactory);
+ }
+
+ @Bean
+ public PriorityPropertyFactory priorityPropertyFactory() {
+ return new PriorityPropertyFactory();
+ }
+
+ @Bean
+ public LastPropertyPlaceholderConfigurer lastPropertyPlaceholderConfigurer() {
+ return new LastPropertyPlaceholderConfigurer();
+ }
+
+ @Bean
+ public DynamicPropertiesImpl dynamicProperties() {
+ return new DynamicPropertiesImpl();
+ }
+
+ @Bean
+ public ConfigObjectFactory configObjectFactory(PriorityPropertyFactory propertyFactory) {
+ return new ConfigObjectFactory(propertyFactory);
+ }
+}
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/LastPropertyPlaceholderConfigurer.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/LastPropertyPlaceholderConfigurer.java
index 769582fa6..ec5054bb7 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/LastPropertyPlaceholderConfigurer.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/LastPropertyPlaceholderConfigurer.java
@@ -22,12 +22,10 @@ import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.Ordered;
-import org.springframework.stereotype.Component;
// do not implements PriorityOrdered, must be Ordered
// because this bean must run after PropertyPlaceholderConfigurer
// this class's purpose: when asked to resolve placeholder, then throw exception directly
-@Component
public class LastPropertyPlaceholderConfigurer implements BeanFactoryPostProcessor, Ordered {
@Override
public int getOrder() {
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/inject/InjectBeanPostProcessor.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/inject/InjectBeanPostProcessor.java
index a5202504d..fbdeff425 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/inject/InjectBeanPostProcessor.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/inject/InjectBeanPostProcessor.java
@@ -23,9 +23,7 @@ import org.apache.servicecomb.config.priority.PriorityPropertyManager;
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
-import org.springframework.stereotype.Component;
-@Component
public class InjectBeanPostProcessor implements BeanPostProcessor {
private final PriorityPropertyManager priorityPropertyManager;
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java
index 16f4a2cb8..aa4248f7e 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/ConfigObjectFactory.java
@@ -28,7 +28,6 @@ import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
import org.apache.servicecomb.foundation.common.utils.JsonUtils;
import org.apache.servicecomb.foundation.common.utils.LambdaMetafactoryUtils;
import org.apache.servicecomb.foundation.common.utils.bean.Setter;
-import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.JavaType;
@@ -42,7 +41,6 @@ import com.fasterxml.jackson.databind.type.TypeFactory;
* ${} or ${not-exist-key} is valid key in archaius<br>
* so this wrapper mechanism will not throw exception even can not find value by placeholder
*/
-@Component
public class ConfigObjectFactory {
private final PriorityPropertyFactory propertyFactory;
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyFactory.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyFactory.java
index f3ec2a72e..0902f65ab 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyFactory.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyFactory.java
@@ -27,11 +27,9 @@ import org.apache.commons.configuration.AbstractConfiguration;
import org.apache.commons.configuration.event.ConfigurationEvent;
import org.apache.commons.configuration.event.ConfigurationListener;
import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
-import org.springframework.stereotype.Component;
import com.netflix.config.ConfigurationManager;
-@Component
public class PriorityPropertyFactory {
private final AbstractConfiguration configuration;
diff --git a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java
index 15a1b5bcf..c1e47ac30 100644
--- a/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java
+++ b/foundations/foundation-config/src/main/java/org/apache/servicecomb/config/priority/PriorityPropertyManager.java
@@ -27,11 +27,9 @@ import java.util.WeakHashMap;
import org.apache.commons.configuration.AbstractConfiguration;
import org.apache.commons.configuration.event.ConfigurationEvent;
import org.apache.commons.configuration.event.ConfigurationListener;
-import org.springframework.stereotype.Component;
import com.netflix.config.ConfigurationManager;
-@Component
public class PriorityPropertyManager {
private final AbstractConfiguration configuration;
diff --git a/foundations/foundation-config/src/main/resources/META-INF/spring.factories b/foundations/foundation-config/src/main/resources/META-INF/spring.factories
new file mode 100644
index 000000000..a575e4d94
--- /dev/null
+++ b/foundations/foundation-config/src/main/resources/META-INF/spring.factories
@@ -0,0 +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.
+## ---------------------------------------------------------------------------
+
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+ org.apache.servicecomb.config.FoundationConfigConfiguration
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClientFilter.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClientFilter.java
index 6fbf8f840..5b7de34dd 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClientFilter.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayClientFilter.java
@@ -35,9 +35,7 @@ import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
-@Component
public class HighwayClientFilter implements ConsumerFilter {
private static final Logger LOGGER = LoggerFactory.getLogger(HighwayClientFilter.class);
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerCodecFilter.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerCodecFilter.java
index 2a3aa824b..d5774c947 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerCodecFilter.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerCodecFilter.java
@@ -33,11 +33,9 @@ import org.apache.servicecomb.foundation.common.utils.AsyncUtils;
import org.apache.servicecomb.swagger.invocation.InvocationType;
import org.apache.servicecomb.swagger.invocation.Response;
import org.apache.servicecomb.transport.highway.message.ResponseHeader;
-import org.springframework.stereotype.Component;
import io.vertx.core.buffer.Buffer;
-@Component
public class HighwayServerCodecFilter implements ProducerFilter {
public static final String NAME = "highway-server-codec";
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/auth/ShaAKSKCipher.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/TransportHighwayConfiguration.java
similarity index 65%
copy from foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/auth/ShaAKSKCipher.java
copy to transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/TransportHighwayConfiguration.java
index e7449745e..b029d6438 100644
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/auth/ShaAKSKCipher.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/TransportHighwayConfiguration.java
@@ -14,22 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.apache.servicecomb.transport.highway;
-package org.apache.servicecomb.foundation.auth;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
-import org.springframework.stereotype.Component;
-
-@Component
-public class ShaAKSKCipher implements Cipher {
- public static final String CIPHER_NAME = "ShaAKSKCipher";
-
- @Override
- public String name() {
- return CIPHER_NAME;
+@Configuration
+public class TransportHighwayConfiguration {
+ @Bean
+ public HighwayServerCodecFilter highwayServerCodecFilter() {
+ return new HighwayServerCodecFilter();
}
- @Override
- public char[] decrypt(char[] encrypted) {
- return encrypted;
+ @Bean
+ public HighwayClientFilter highwayClientFilter() {
+ return new HighwayClientFilter();
}
}
diff --git a/transports/transport-highway/src/main/resources/META-INF/spring.factories b/transports/transport-highway/src/main/resources/META-INF/spring.factories
new file mode 100644
index 000000000..bbc7ad812
--- /dev/null
+++ b/transports/transport-highway/src/main/resources/META-INF/spring.factories
@@ -0,0 +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.
+## ---------------------------------------------------------------------------
+
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+ org.apache.servicecomb.transport.highway.TransportHighwayConfiguration