Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement and Bugfix in 2.7.1 #3666

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
562a126
Merge pull request #15 from alibaba/master
mercyblitz Nov 6, 2017
926baab
Merge remote-tracking branch 'upstream/master'
mercyblitz Dec 26, 2017
562ce4f
Merge branch 'master' of https://github.com/mercyblitz/dubbo
mercyblitz Mar 12, 2018
4f34540
Manually merge pull request #1486, to make travis ci and codecov work…
chickenlj Mar 20, 2018
1e5b28f
Polish alibaba/dubbo#1306
mercyblitz Mar 30, 2018
24ebffc
Merge remote-tracking branch 'dubbo_remote/master'
mercyblitz Apr 15, 2018
4239a19
Merge branch 'master' into 2.5.x
mercyblitz Apr 15, 2018
0a570b7
Merge branch 'master' into 2.5.x
mercyblitz Apr 15, 2018
feac608
Merge pull request #21 from mercyblitz/2.5.x
mercyblitz Apr 15, 2018
93591f0
Optimize imports
mercyblitz Apr 15, 2018
d57343e
Optimize imports
mercyblitz Apr 15, 2018
d428f5f
Remove invalid JavaDoc
mercyblitz Apr 23, 2018
5d72ddf
Update DubboConfigBinder.java
mercyblitz Apr 23, 2018
a7d176f
Merge remote-tracking branch 'origin/master'
mercyblitz Apr 23, 2018
4d6b1fa
Merge remote-tracking branch 'upstream/master'
mercyblitz Apr 23, 2018
5bab141
Fix apache/incubator-dubbo#1653
mercyblitz Apr 23, 2018
f12ecee
Merge remote-tracking branch 'upstream/master'
mercyblitz Jun 7, 2018
7faf93c
Merge remote-tracking branch 'upstream/master'
mercyblitz Jun 8, 2018
88f3af3
Add 2.7.x branch
mercyblitz Jun 8, 2018
d1c04fc
Remove useless fiels
mercyblitz Jun 8, 2018
3fb7026
Merge remote-tracking branch 'upstream/master'
mercyblitz Jun 11, 2018
99fac1d
Merge remote-tracking branch 'upstream/master' into 2.7.x
mercyblitz Jun 11, 2018
4d6dd46
Merge remote-tracking branch 'upstream/master'
mercyblitz Jun 22, 2018
47e26f2
RestSevice demo code
mercyblitz Jun 22, 2018
f6cc206
Merge remote-tracking branch 'upstream/master' into 2.7.x
mercyblitz Jul 25, 2018
9f06b93
Merge pull request #24 from mercyblitz/2.7.x
mercyblitz Jul 25, 2018
405b9b8
Merge remote-tracking branch 'dubbo_remote/master'
mercyblitz Aug 10, 2018
5286787
Merge pull request #25 from apache/master
mercyblitz Oct 15, 2018
c67f82d
Merge remote-tracking branch 'upstream/master'
mercyblitz Dec 7, 2018
bbd397a
Merge remote-tracking branch 'upstream/master'
mercyblitz Mar 14, 2019
23afeac
Polish apache/incubator-dubbo#3429 : Fix The NPE issue
mercyblitz Mar 14, 2019
16bc383
Polish apache/incubator-dubbo#1306 : @Reference bean name conflict
mercyblitz Mar 14, 2019
ca79632
Polish apache/incubator-dubbo#3251 : @Service supports the hierarchic…
mercyblitz Mar 14, 2019
438b50b
Polish apache/incubator-dubbo#3615 : SpringStatusChecker execute erro…
mercyblitz Mar 14, 2019
b4f783b
Polish apache/incubator-dubbo#3193 : Change the default behavior of @…
mercyblitz Mar 14, 2019
4b5b996
Polish apache/incubator-dubbo#3189 : Simplify externalized configurat…
mercyblitz Mar 14, 2019
deecedc
Remove useless module
mercyblitz Mar 14, 2019
49f6d41
Polish apache/incubator-dubbo#3582 : nacos support on 2.7
mercyblitz Mar 14, 2019
02689eb
Merge remote-tracking branch 'upstream/2.7.1-release'
mercyblitz Mar 15, 2019
7b9f76d
Polish apache/incubator-dubbo#3582 : Add Path
mercyblitz Mar 15, 2019
c1b942d
Polish apache/incubator-dubbo#3582 : Add Enabled logic
mercyblitz Mar 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* 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.beans.factory.annotation;

import static org.apache.dubbo.common.Constants.CONSUMERS_CATEGORY;
import static org.apache.dubbo.common.Constants.DEFAULT_PROTOCOL;
import static org.apache.dubbo.common.Constants.PROVIDERS_CATEGORY;
import static org.apache.dubbo.config.spring.util.AnnotationUtils.resolveInterfaceName;
import static org.springframework.util.StringUtils.arrayToCommaDelimitedString;
import static org.springframework.util.StringUtils.hasText;

import org.apache.dubbo.common.Constants;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.registry.Registry;

import org.springframework.core.env.Environment;

/**
* The Bean Name Builder for the annotations {@link Service} and {@link Reference}
* <p>
* The naming rule is consistent with the the implementation {@link Registry} that is based on the service-name aware
* infrastructure, e.g Spring Cloud, Cloud Native and so on.
* <p>
* The pattern of bean name : ${category}:${protocol}:${serviceInterface}:${version}:${group}.
* <p>
* ${version} and ${group} are optional.
*
* @since 2.6.6
*/
class AnnotationBeanNameBuilder {

private static final String SEPARATOR = ":";

// Required properties

private final String category;

private final String protocol;

private final String interfaceClassName;

// Optional properties

private String version;

private String group;

private Environment environment;

private AnnotationBeanNameBuilder(String category, String protocol, String interfaceClassName) {
this.category = category;
this.protocol = protocol;
this.interfaceClassName = interfaceClassName;
}

private AnnotationBeanNameBuilder(Service service, Class<?> interfaceClass) {
this(PROVIDERS_CATEGORY, resolveProtocol(service.protocol()), resolveInterfaceName(service, interfaceClass));
this.group(service.group());
this.version(service.version());
}

private AnnotationBeanNameBuilder(Reference reference, Class<?> interfaceClass) {
this(CONSUMERS_CATEGORY, resolveProtocol(reference.protocol()), resolveInterfaceName(reference, interfaceClass));
this.group(reference.group());
this.version(reference.version());
}

public static AnnotationBeanNameBuilder create(Service service, Class<?> interfaceClass) {
return new AnnotationBeanNameBuilder(service, interfaceClass);
}

public static AnnotationBeanNameBuilder create(Reference reference, Class<?> interfaceClass) {
return new AnnotationBeanNameBuilder(reference, interfaceClass);
}

private static void append(StringBuilder builder, String value) {
if (hasText(value)) {
builder.append(SEPARATOR).append(value);
}
}

public AnnotationBeanNameBuilder group(String group) {
this.group = group;
return this;
}

public AnnotationBeanNameBuilder version(String version) {
this.version = version;
return this;
}

public AnnotationBeanNameBuilder environment(Environment environment) {
this.environment = environment;
return this;
}

/**
* Resolve the protocol
*
* @param protocols one or more protocols
* @return if <code>protocols</code> == <code>null</code>, it will return
* {@link Constants#DEFAULT_PROTOCOL "dubbo"} as the default protocol
* @see Constants#DEFAULT_PROTOCOL
*/
private static String resolveProtocol(String... protocols) {
String protocol = arrayToCommaDelimitedString(protocols);
return hasText(protocol) ? protocol : DEFAULT_PROTOCOL;
}

/**
* Build bean name while resolve the placeholders if possible.
*
* @return pattern : ${category}:${protocol}:${serviceInterface}:${version}:${group}
*/
public String build() {
// Append the required properties
StringBuilder beanNameBuilder = new StringBuilder(category);
append(beanNameBuilder, protocol);
append(beanNameBuilder, interfaceClassName);
// Append the optional properties
append(beanNameBuilder, version);
append(beanNameBuilder, group);
String beanName = beanNameBuilder.toString();
// Resolve placeholders
return environment != null ? environment.resolvePlaceholders(beanName) : beanName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.dubbo.config.AbstractConfig;
import org.apache.dubbo.config.spring.context.annotation.DubboConfigBindingRegistrar;
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfigBinding;
import org.apache.dubbo.config.spring.context.config.DubboConfigBeanCustomizer;
import org.apache.dubbo.config.spring.context.properties.DefaultDubboConfigBinder;
import org.apache.dubbo.config.spring.context.properties.DubboConfigBinder;

Expand All @@ -30,8 +31,16 @@
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.env.Environment;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import static org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors;

/**
* Dubbo Config Binding {@link BeanPostProcessor}
*
Expand Down Expand Up @@ -62,6 +71,8 @@ public class DubboConfigBindingBeanPostProcessor implements BeanPostProcessor, A

private boolean ignoreInvalidFields = true;

private List<DubboConfigBeanCustomizer> configBeanCustomizers = Collections.emptyList();

/**
* @param prefix the prefix of Configuration Properties
* @param beanName the binding Bean Name
Expand All @@ -80,18 +91,34 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro

AbstractConfig dubboConfig = (AbstractConfig) bean;

dubboConfigBinder.bind(prefix, dubboConfig);
bind(prefix, dubboConfig);

customize(beanName, dubboConfig);

if (log.isInfoEnabled()) {
log.info("The properties of bean [name : " + beanName + "] have been binding by prefix of " +
"configuration properties : " + prefix);
}
}

return bean;

}

private void bind(String prefix, AbstractConfig dubboConfig) {

dubboConfigBinder.bind(prefix, dubboConfig);

if (log.isInfoEnabled()) {
log.info("The properties of bean [name : " + beanName + "] have been binding by prefix of " +
"configuration properties : " + prefix);
}
}

private void customize(String beanName, AbstractConfig dubboConfig) {

for (DubboConfigBeanCustomizer customizer : configBeanCustomizers) {
customizer.customize(beanName, dubboConfig);
}

}

public boolean isIgnoreUnknownFields() {
return ignoreUnknownFields;
}
Expand Down Expand Up @@ -129,6 +156,14 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
@Override
public void afterPropertiesSet() throws Exception {

initDubboConfigBinder();

initConfigBeanCustomizers();

}

private void initDubboConfigBinder() {

if (dubboConfigBinder == null) {
try {
dubboConfigBinder = applicationContext.getBean(DubboConfigBinder.class);
Expand All @@ -146,6 +181,16 @@ public void afterPropertiesSet() throws Exception {

}

private void initConfigBeanCustomizers() {

Collection<DubboConfigBeanCustomizer> configBeanCustomizers =
beansOfTypeIncludingAncestors(applicationContext, DubboConfigBeanCustomizer.class).values();

this.configBeanCustomizers = new ArrayList<DubboConfigBeanCustomizer>(configBeanCustomizers);

AnnotationAwareOrderComparator.sort(this.configBeanCustomizers);
}

/**
* Create {@link DubboConfigBinder} instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
*/
package org.apache.dubbo.config.spring.beans.factory.annotation;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.spring.ReferenceBean;
import org.apache.dubbo.config.spring.ServiceBean;
Expand All @@ -30,16 +41,6 @@
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
* {@link org.springframework.beans.factory.config.BeanPostProcessor} implementation
* that Consumer service {@link Reference} annotated fields
Expand Down Expand Up @@ -155,7 +156,18 @@ private ReferenceBeanInvocationHandler(ReferenceBean referenceBean) {

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return method.invoke(bean, args);
Object result = null;
try {
if (bean == null) { // If the bean is not initialized, invoke init()
// issue: https://github.com/apache/incubator-dubbo/issues/3429
init();
}
result = method.invoke(bean, args);
} catch (InvocationTargetException e) {
// re-throws the actual Exception.
throw e.getTargetException();
}
return result;
}

private void init() {
Expand All @@ -176,7 +188,9 @@ protected String buildInjectedObjectCacheKey(Reference reference, Object bean, S

private String buildReferencedBeanName(Reference reference, Class<?> injectedType) {

ServiceBeanNameBuilder builder = ServiceBeanNameBuilder.create(reference, injectedType, getEnvironment());
AnnotationBeanNameBuilder builder = AnnotationBeanNameBuilder.create(reference, injectedType);

builder.environment(getEnvironment());

return getEnvironment().resolvePlaceholders(builder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@
*/
package org.apache.dubbo.config.spring.beans.factory.annotation;

import static org.apache.dubbo.config.spring.util.ObjectUtils.of;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;
import static org.springframework.context.annotation.AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR;
import static org.springframework.core.annotation.AnnotationUtils.findAnnotation;
import static org.springframework.util.ClassUtils.resolveClassName;

import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.config.MethodConfig;
Expand Down Expand Up @@ -52,18 +64,6 @@
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import static org.apache.dubbo.config.spring.util.ObjectUtils.of;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;
import static org.springframework.context.annotation.AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR;
import static org.springframework.core.annotation.AnnotationUtils.findAnnotation;
import static org.springframework.util.ClassUtils.resolveClassName;

/**
* {@link Service} Annotation
* {@link BeanDefinitionRegistryPostProcessor Bean Definition Registry Post Processor}
Expand Down Expand Up @@ -290,8 +290,9 @@ private void registerServiceBean(BeanDefinitionHolder beanDefinitionHolder, Bean
*/
private String generateServiceBeanName(Service service, Class<?> interfaceClass, String annotatedServiceBeanName) {

ServiceBeanNameBuilder builder = ServiceBeanNameBuilder.create(service, interfaceClass, environment);
AnnotationBeanNameBuilder builder = AnnotationBeanNameBuilder.create(service, interfaceClass);

builder.environment(environment);

return builder.build();

Expand All @@ -316,8 +317,9 @@ private Class<?> resolveServiceInterfaceClass(Class<?> annotatedServiceBeanClass
}

if (interfaceClass == null) {

Class<?>[] allInterfaces = annotatedServiceBeanClass.getInterfaces();
// Find all interfaces from the annotated class
// To resolve an issue : https://github.com/apache/incubator-dubbo/issues/3251
Class<?>[] allInterfaces = ClassUtils.getAllInterfacesForClass(annotatedServiceBeanClass);

if (allInterfaces.length > 0) {
interfaceClass = allInterfaces[0];
Expand Down
Loading