1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

Polish spring-cloud-incubator/spring-cloud-alibaba#559 : Resolve BeanCurrentlyInCreationException issue

This commit is contained in:
mercyblitz 2019-04-17 12:51:27 +08:00
parent aef27e885e
commit 0a9930c8c2
3 changed files with 15 additions and 9 deletions

View File

@ -56,7 +56,7 @@ import java.util.function.Supplier;
public class DubboMetadataAutoConfiguration {
@Autowired
private DubboServiceMetadataRepository dubboServiceMetadataRepository;
private ObjectProvider<DubboServiceMetadataRepository> dubboServiceMetadataRepository;
@Autowired
private MetadataResolver metadataResolver;
@ -100,7 +100,7 @@ public class DubboMetadataAutoConfiguration {
}
private void publishServiceRestMetadata(ServiceBean serviceBean) {
dubboServiceMetadataRepository.publishServiceRestMetadata(metadataResolver.resolveServiceRestMetadata(serviceBean));
dubboServiceMetadataRepository.getIfAvailable().publishServiceRestMetadata(metadataResolver.resolveServiceRestMetadata(serviceBean));
}
private void unExportDubboMetadataConfigService() {

View File

@ -23,6 +23,7 @@ import org.apache.dubbo.config.ServiceConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@ -45,7 +46,7 @@ public class DubboMetadataServiceExporter {
private ApplicationConfig applicationConfig;
@Autowired
private DubboMetadataService dubboMetadataService;
private ObjectProvider<DubboMetadataService> dubboMetadataService;
@Autowired
private Supplier<ProtocolConfig> protocolConfigSupplier;
@ -74,7 +75,7 @@ public class DubboMetadataServiceExporter {
serviceConfig.setVersion(DubboMetadataService.VERSION);
// Use current Spring application name as the Dubbo Service group
serviceConfig.setGroup(currentApplicationName);
serviceConfig.setRef(dubboMetadataService);
serviceConfig.setRef(dubboMetadataService.getIfAvailable());
serviceConfig.setApplication(applicationConfig);
serviceConfig.setProtocol(protocolConfigSupplier.get());

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.alibaba.dubbo.metadata.ServiceRestMetadata;
import org.springframework.cloud.alibaba.dubbo.metadata.repository.DubboServiceMetadataRepository;
@ -44,14 +45,14 @@ public class IntrospectiveDubboMetadataService implements DubboMetadataService {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private DubboServiceMetadataRepository dubboServiceMetadataRepository;
private ObjectProvider<DubboServiceMetadataRepository> dubboServiceMetadataRepository;
@Autowired
private JSONUtils jsonUtils;
@Override
public String getServiceRestMetadata() {
Set<ServiceRestMetadata> serviceRestMetadata = dubboServiceMetadataRepository.getServiceRestMetadata();
Set<ServiceRestMetadata> serviceRestMetadata = getRepository().getServiceRestMetadata();
String serviceRestMetadataJsonConfig = null;
if (!isEmpty(serviceRestMetadata)) {
serviceRestMetadataJsonConfig = jsonUtils.toJSON(serviceRestMetadata);
@ -61,12 +62,12 @@ public class IntrospectiveDubboMetadataService implements DubboMetadataService {
@Override
public Set<String> getAllServiceKeys() {
return dubboServiceMetadataRepository.getAllServiceKeys();
return getRepository().getAllServiceKeys();
}
@Override
public Map<String, String> getAllExportedURLs() {
Map<String, List<URL>> allExportedUrls = dubboServiceMetadataRepository.getAllExportedUrls();
Map<String, List<URL>> allExportedUrls = getRepository().getAllExportedUrls();
if (isEmpty(allExportedUrls)) {
if (logger.isDebugEnabled()) {
logger.debug("There is no registered URL.");
@ -85,7 +86,11 @@ public class IntrospectiveDubboMetadataService implements DubboMetadataService {
@Override
public String getExportedURLs(String serviceInterface, String group, String version) {
List<URL> urls = dubboServiceMetadataRepository.getExportedURLs(serviceInterface, group, version);
List<URL> urls = getRepository().getExportedURLs(serviceInterface, group, version);
return jsonUtils.toJSON(urls);
}
private DubboServiceMetadataRepository getRepository() {
return dubboServiceMetadataRepository.getIfAvailable();
}
}