This is an automated email from the ASF dual-hosted git repository.
mercyblitz pushed a commit to branch 2.7.0-release
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/2.7.0-release by this push:
new 3c38f20 Remove deprecated AnnotationBean, please refer #1485 for the
new method to replace. (#3232)
3c38f20 is described below
commit 3c38f20a6736e8f5e9679383d7c1f5da80f54795
Author: ken.lj <[email protected]>
AuthorDate: Tue Jan 15 15:00:01 2019 +0800
Remove deprecated AnnotationBean, please refer #1485 for the new method to
replace. (#3232)
---
.../CompatibleAnnotationBeanDefinitionParser.java | 4 +-
.../apache/dubbo/config/spring/AnnotationBean.java | 321 ---------------------
.../schema/AnnotationBeanDefinitionParser.java | 4 +-
.../src/main/resources/META-INF/compat/dubbo.xsd | 25 --
4 files changed, 2 insertions(+), 352 deletions(-)
diff --git
a/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/schema/CompatibleAnnotationBeanDefinitionParser.java
b/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/schema/CompatibleAnnotationBeanDefinitionParser.java
index 66d6ac2..1172591 100644
---
a/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/schema/CompatibleAnnotationBeanDefinitionParser.java
+++
b/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/schema/CompatibleAnnotationBeanDefinitionParser.java
@@ -16,11 +16,9 @@
*/
package org.apache.dubbo.config.spring.schema;
-import org.apache.dubbo.config.spring.AnnotationBean;
import
org.apache.dubbo.config.spring.beans.factory.annotation.CompatibleReferenceAnnotationBeanPostProcessor;
import
org.apache.dubbo.config.spring.beans.factory.annotation.CompatibleServiceAnnotationBeanPostProcessor;
import org.apache.dubbo.config.spring.util.BeanRegistrar;
-
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -34,7 +32,7 @@ import static
org.springframework.util.StringUtils.commaDelimitedListToStringArr
import static org.springframework.util.StringUtils.trimArrayElements;
/**
- * {@link AnnotationBean} {@link BeanDefinitionParser}
+ * {@link BeanDefinitionParser}
*
* @see CompatibleServiceAnnotationBeanPostProcessor
* @see CompatibleReferenceAnnotationBeanPostProcessor
diff --git
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java
deleted file mode 100644
index 9af02a1..0000000
---
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/AnnotationBean.java
+++ /dev/null
@@ -1,321 +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 org.apache.dubbo.config.spring;
-
-import org.apache.dubbo.common.Constants;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.common.utils.ConcurrentHashSet;
-import org.apache.dubbo.common.utils.ReflectUtils;
-import org.apache.dubbo.config.AbstractConfig;
-import org.apache.dubbo.config.ApplicationConfig;
-import org.apache.dubbo.config.ConsumerConfig;
-import org.apache.dubbo.config.ModuleConfig;
-import org.apache.dubbo.config.MonitorConfig;
-import org.apache.dubbo.config.ProtocolConfig;
-import org.apache.dubbo.config.ProviderConfig;
-import org.apache.dubbo.config.RegistryConfig;
-import org.apache.dubbo.config.ServiceConfig;
-import org.apache.dubbo.config.annotation.Reference;
-import org.apache.dubbo.config.annotation.Service;
-
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- * AnnotationBean
- *
- * @export
- */
-@Deprecated
-public class AnnotationBean extends AbstractConfig implements DisposableBean,
BeanFactoryPostProcessor, BeanPostProcessor, ApplicationContextAware {
-
- private static final long serialVersionUID = -7582802454287589552L;
-
- private static final Logger logger = LoggerFactory.getLogger(Logger.class);
- private final Set<ServiceConfig<?>> serviceConfigs = new
ConcurrentHashSet<ServiceConfig<?>>();
- private final ConcurrentMap<String, ReferenceBean<?>> referenceConfigs =
new ConcurrentHashMap<String, ReferenceBean<?>>();
- private String annotationPackage;
- private String[] annotationPackages;
- private ApplicationContext applicationContext;
-
- public String getPackage() {
- return annotationPackage;
- }
-
- public void setPackage(String annotationPackage) {
- this.annotationPackage = annotationPackage;
- this.annotationPackages = (annotationPackage == null ||
annotationPackage.length() == 0) ? null
- : Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
- }
-
- @Override
- public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
- this.applicationContext = applicationContext;
- }
-
- @Override
- public void postProcessBeanFactory(ConfigurableListableBeanFactory
beanFactory)
- throws BeansException {
- if (annotationPackage == null || annotationPackage.length() == 0) {
- return;
- }
- if (beanFactory instanceof BeanDefinitionRegistry) {
- try {
- // init scanner
- Class<?> scannerClass =
ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
- Object scanner = scannerClass.getConstructor(new
Class<?>[]{BeanDefinitionRegistry.class,
boolean.class}).newInstance((BeanDefinitionRegistry) beanFactory, true);
- // add filter
- Class<?> filterClass =
ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
- Object filter =
filterClass.getConstructor(Class.class).newInstance(Service.class);
- Method addIncludeFilter =
scannerClass.getMethod("addIncludeFilter",
ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
- addIncludeFilter.invoke(scanner, filter);
- // scan packages
- String[] packages =
Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
- Method scan = scannerClass.getMethod("scan", String[].class);
- scan.invoke(scanner, new Object[]{packages});
- } catch (Throwable e) {
- // spring 2.0
- }
- }
- }
-
- @Override
- public void destroy() {
- // no need to destroy here
- // see
org.apache.dubbo.config.spring.extension.SpringExtensionFactory.ShutdownHookListener
- /*
- for (ServiceConfig<?> serviceConfig : serviceConfigs) {
- try {
- serviceConfig.unexport();
- } catch (Throwable e) {
- logger.error(e.getMessage(), e);
- }
- }
-
- for (ReferenceConfig<?> referenceConfig : referenceConfigs.values()) {
- try {
- referenceConfig.destroy();
- } catch (Throwable e) {
- logger.error(e.getMessage(), e);
- }
- }
- */
- }
-
- @Override
- public Object postProcessAfterInitialization(Object bean, String beanName)
- throws BeansException {
- if (!isMatchPackage(bean)) {
- return bean;
- }
- Service service = bean.getClass().getAnnotation(Service.class);
- if (service != null) {
- ServiceBean<Object> serviceConfig = new
ServiceBean<Object>(service);
- serviceConfig.setRef(bean);
- if (void.class.equals(service.interfaceClass())
- && "".equals(service.interfaceName())) {
- if (bean.getClass().getInterfaces().length > 0) {
-
serviceConfig.setInterface(bean.getClass().getInterfaces()[0]);
- } else {
- throw new IllegalStateException("Failed to export remote
service class " + bean.getClass().getName() + ", cause: The @Service undefined
interfaceClass or interfaceName, and the service class unimplemented any
interfaces.");
- }
- }
- if (applicationContext != null) {
- serviceConfig.setApplicationContext(applicationContext);
- if (service.registry().length > 0) {
- List<RegistryConfig> registryConfigs = new
ArrayList<RegistryConfig>();
- for (String registryId : service.registry()) {
- if (registryId != null && registryId.length() > 0) {
-
registryConfigs.add(applicationContext.getBean(registryId,
RegistryConfig.class));
- }
- }
- serviceConfig.setRegistries(registryConfigs);
- }
- if (service.provider().length() > 0) {
-
serviceConfig.setProvider(applicationContext.getBean(service.provider(),
ProviderConfig.class));
- }
- if (service.monitor().length() > 0) {
-
serviceConfig.setMonitor(applicationContext.getBean(service.monitor(),
MonitorConfig.class));
- }
- if (service.application().length() > 0) {
-
serviceConfig.setApplication(applicationContext.getBean(service.application(),
ApplicationConfig.class));
- }
- if (service.module().length() > 0) {
-
serviceConfig.setModule(applicationContext.getBean(service.module(),
ModuleConfig.class));
- }
- if (service.protocol().length > 0) {
- List<ProtocolConfig> protocolConfigs = new
ArrayList<ProtocolConfig>();
- for (String protocolId : service.protocol()) {
- if (protocolId != null && protocolId.length() > 0) {
-
protocolConfigs.add(applicationContext.getBean(protocolId,
ProtocolConfig.class));
- }
- }
- serviceConfig.setProtocols(protocolConfigs);
- }
- if (service.tag().length() > 0) {
- serviceConfig.setTag(service.tag());
- }
- try {
- serviceConfig.afterPropertiesSet();
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
- serviceConfigs.add(serviceConfig);
- serviceConfig.export();
- }
- return bean;
- }
-
- @Override
- public Object postProcessBeforeInitialization(Object bean, String beanName)
- throws BeansException {
- if (!isMatchPackage(bean)) {
- return bean;
- }
- Method[] methods = bean.getClass().getMethods();
- for (Method method : methods) {
- String name = method.getName();
- if (name.length() > 3 && name.startsWith("set")
- && method.getParameterTypes().length == 1
- && Modifier.isPublic(method.getModifiers())
- && !Modifier.isStatic(method.getModifiers())) {
- try {
- Reference reference =
method.getAnnotation(Reference.class);
- if (reference != null) {
- Object value = refer(reference,
method.getParameterTypes()[0]);
- if (value != null) {
- method.invoke(bean, value);
- }
- }
- } catch (Throwable e) {
- logger.error("Failed to init remote service reference at
method " + name + " in class " + bean.getClass().getName() + ", cause: " +
e.getMessage(), e);
- }
- }
- }
- Field[] fields = bean.getClass().getDeclaredFields();
- for (Field field : fields) {
- try {
- if (!field.isAccessible()) {
- field.setAccessible(true);
- }
- Reference reference = field.getAnnotation(Reference.class);
- if (reference != null) {
- Object value = refer(reference, field.getType());
- if (value != null) {
- field.set(bean, value);
- }
- }
- } catch (Throwable e) {
- logger.error("Failed to init remote service reference at field
" + field.getName() + " in class " + bean.getClass().getName() + ", cause: " +
e.getMessage(), e);
- }
- }
- return bean;
- }
-
- private Object refer(Reference reference, Class<?> referenceClass) {
//method.getParameterTypes()[0]
- String interfaceName;
- if (!"".equals(reference.interfaceName())) {
- interfaceName = reference.interfaceName();
- } else if (!void.class.equals(reference.interfaceClass())) {
- interfaceName = reference.interfaceClass().getName();
- } else if (referenceClass.isInterface()) {
- interfaceName = referenceClass.getName();
- } else {
- throw new IllegalStateException("The @Reference undefined
interfaceClass or interfaceName, and the property type " +
referenceClass.getName() + " is not a interface.");
- }
- String key = reference.group() + "/" + interfaceName + ":" +
reference.version();
- ReferenceBean<?> referenceConfig = referenceConfigs.get(key);
- if (referenceConfig == null) {
- referenceConfig = new ReferenceBean<Object>(reference);
- if (void.class.equals(reference.interfaceClass())
- && "".equals(reference.interfaceName())
- && referenceClass.isInterface()) {
- referenceConfig.setInterface(referenceClass);
- }
- if (applicationContext != null) {
- referenceConfig.setApplicationContext(applicationContext);
- if (reference.registry().length > 0) {
- List<RegistryConfig> registryConfigs = new
ArrayList<RegistryConfig>();
- for (String registryId : reference.registry()) {
- if (registryId != null && registryId.length() > 0) {
-
registryConfigs.add(applicationContext.getBean(registryId,
RegistryConfig.class));
- }
- }
- referenceConfig.setRegistries(registryConfigs);
- }
- if (reference.consumer().length() > 0) {
-
referenceConfig.setConsumer(applicationContext.getBean(reference.consumer(),
ConsumerConfig.class));
- }
- if (reference.monitor().length() > 0) {
-
referenceConfig.setMonitor(applicationContext.getBean(reference.monitor(),
MonitorConfig.class));
- }
- if (reference.application().length() > 0) {
-
referenceConfig.setApplication(applicationContext.getBean(reference.application(),
ApplicationConfig.class));
- }
- if (reference.module().length() > 0) {
-
referenceConfig.setModule(applicationContext.getBean(reference.module(),
ModuleConfig.class));
- }
- if (reference.consumer().length() > 0) {
-
referenceConfig.setConsumer(applicationContext.getBean(reference.consumer(),
ConsumerConfig.class));
- }
- try {
- referenceConfig.afterPropertiesSet();
- } catch (RuntimeException e) {
- throw e;
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
- referenceConfigs.putIfAbsent(key, referenceConfig);
- referenceConfig = referenceConfigs.get(key);
- }
- return referenceConfig.get();
- }
-
- private boolean isMatchPackage(Object bean) {
- if (annotationPackages == null || annotationPackages.length == 0) {
- return true;
- }
- String beanClassName = bean.getClass().getName();
- for (String pkg : annotationPackages) {
- if (beanClassName.startsWith(pkg)) {
- return true;
- }
- }
- return false;
- }
-
-}
diff --git
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/AnnotationBeanDefinitionParser.java
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/AnnotationBeanDefinitionParser.java
index 918c916..4a8e963 100644
---
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/AnnotationBeanDefinitionParser.java
+++
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/AnnotationBeanDefinitionParser.java
@@ -16,7 +16,6 @@
*/
package org.apache.dubbo.config.spring.schema;
-import org.apache.dubbo.config.spring.AnnotationBean;
import
org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor;
import
org.apache.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor;
import org.apache.dubbo.config.spring.util.BeanRegistrar;
@@ -26,7 +25,6 @@ import
org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import
org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
-import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
@@ -34,7 +32,7 @@ import static
org.springframework.util.StringUtils.commaDelimitedListToStringArr
import static org.springframework.util.StringUtils.trimArrayElements;
/**
- * {@link AnnotationBean} {@link BeanDefinitionParser}
+ * @link BeanDefinitionParser}
*
* @see ServiceAnnotationBeanPostProcessor
* @see ReferenceAnnotationBeanPostProcessor
diff --git
a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd
b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd
index 30e8f14..4f0b1bf 100644
---
a/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd
+++
b/dubbo-config/dubbo-config-spring/src/main/resources/META-INF/compat/dubbo.xsd
@@ -1310,31 +1310,6 @@
</xsd:complexContent>
</xsd:complexType>
- <xsd:complexType name="annotationType">
- <xsd:attribute name="id" type="xsd:ID">
- <xsd:annotation>
- <xsd:documentation><![CDATA[ The unique identifier for a bean.
]]></xsd:documentation>
- </xsd:annotation>
- </xsd:attribute>
- <xsd:attribute name="package" type="xsd:string">
- <xsd:annotation>
- <xsd:documentation><![CDATA[ The scan package.
]]></xsd:documentation>
- </xsd:annotation>
- </xsd:attribute>
- </xsd:complexType>
-
- <xsd:element name="annotation" type="annotationType">
- <xsd:annotation>
- <xsd:documentation><![CDATA[ The annotation config
]]></xsd:documentation>
- <xsd:appinfo>
- <tool:annotation>
- <tool:exports
type="org.apache.dubbo.config.ServiceConfig"/>
- <tool:exports
type="org.apache.dubbo.config.ReferenceConfig"/>
- </tool:annotation>
- </xsd:appinfo>
- </xsd:annotation>
- </xsd:element>
-
<xsd:element name="application" type="applicationType">
<xsd:annotation>
<xsd:documentation><![CDATA[ The application config
]]></xsd:documentation>