Ignore start if scope model is LifeCycleManagedExternally (#12985)
This commit is contained in:
parent
0bfd54cea4
commit
bfa46f59eb
|
|
@ -227,8 +227,13 @@ public class ReferenceConfig<T> extends ReferenceConfigBase<T> {
|
|||
}
|
||||
|
||||
if (ref == null) {
|
||||
// ensure start module, compatible with old api usage
|
||||
getScopeModel().getDeployer().start();
|
||||
if (getScopeModel().isLifeCycleManagedExternally()) {
|
||||
// prepare model for reference
|
||||
getScopeModel().getDeployer().prepare();
|
||||
} else {
|
||||
// ensure start module, compatible with old api usage
|
||||
getScopeModel().getDeployer().start();
|
||||
}
|
||||
|
||||
init(check);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -295,8 +295,13 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
|
|||
return;
|
||||
}
|
||||
|
||||
// ensure start module, compatible with old api usage
|
||||
getScopeModel().getDeployer().start();
|
||||
if (getScopeModel().isLifeCycleManagedExternally()) {
|
||||
// prepare model for reference
|
||||
getScopeModel().getDeployer().prepare();
|
||||
} else {
|
||||
// ensure start module, compatible with old api usage
|
||||
getScopeModel().getDeployer().start();
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
if (this.exported) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.apache.dubbo.common.utils.Assert;
|
|||
import org.apache.dubbo.common.utils.ClassUtils;
|
||||
import org.apache.dubbo.common.utils.StringUtils;
|
||||
import org.apache.dubbo.config.ReferenceConfig;
|
||||
import org.apache.dubbo.config.spring.context.DubboConfigApplicationListener;
|
||||
import org.apache.dubbo.config.spring.context.DubboConfigBeanInitializer;
|
||||
import org.apache.dubbo.config.spring.reference.ReferenceAttributes;
|
||||
import org.apache.dubbo.config.spring.reference.ReferenceBeanManager;
|
||||
|
|
@ -53,6 +54,7 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_DUBBO_BEAN_INITIALIZER;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROXY_FAILED;
|
||||
|
||||
|
||||
|
|
@ -143,6 +145,9 @@ public class ReferenceBean<T> implements FactoryBean<T>,
|
|||
//actual reference config
|
||||
private ReferenceConfig referenceConfig;
|
||||
|
||||
// ReferenceBeanManager
|
||||
private ReferenceBeanManager referenceBeanManager;
|
||||
|
||||
// Registration sources of this reference, may be xml file or annotation location
|
||||
private List<Map<String,Object>> sources = new ArrayList<>();
|
||||
|
||||
|
|
@ -251,7 +256,7 @@ public class ReferenceBean<T> implements FactoryBean<T>,
|
|||
}
|
||||
Assert.notNull(this.interfaceName, "The interface name of ReferenceBean is not initialized");
|
||||
|
||||
ReferenceBeanManager referenceBeanManager = beanFactory.getBean(ReferenceBeanManager.BEAN_NAME, ReferenceBeanManager.class);
|
||||
this.referenceBeanManager = beanFactory.getBean(ReferenceBeanManager.BEAN_NAME, ReferenceBeanManager.class);
|
||||
referenceBeanManager.addReference(this);
|
||||
}
|
||||
|
||||
|
|
@ -387,7 +392,9 @@ public class ReferenceBean<T> implements FactoryBean<T>,
|
|||
|
||||
private Object getCallProxy() throws Exception {
|
||||
if (referenceConfig == null) {
|
||||
throw new IllegalStateException("ReferenceBean is not ready yet, please make sure to call reference interface method after dubbo is started.");
|
||||
referenceBeanManager.initReferenceBean(this);
|
||||
applicationContext.getBean(DubboConfigApplicationListener.class.getName(), DubboConfigApplicationListener.class).init();
|
||||
logger.warn(CONFIG_DUBBO_BEAN_INITIALIZER, "", "", "ReferenceBean is not ready yet, please make sure to call reference interface method after dubbo is started.");
|
||||
}
|
||||
//get reference proxy
|
||||
//Subclasses should synchronize on the given Object if they perform any sort of extended singleton creation phase.
|
||||
|
|
|
|||
|
|
@ -16,21 +16,22 @@
|
|||
*/
|
||||
package org.apache.dubbo.config.spring.context;
|
||||
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_DUBBO_BEAN_NOT_FOUND;
|
||||
import static org.springframework.util.ObjectUtils.nullSafeEquals;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.config.spring.context.event.DubboConfigInitEvent;
|
||||
import org.apache.dubbo.config.spring.util.DubboBeanUtils;
|
||||
import org.apache.dubbo.rpc.model.ModuleModel;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_DUBBO_BEAN_NOT_FOUND;
|
||||
import static org.springframework.util.ObjectUtils.nullSafeEquals;
|
||||
|
||||
/**
|
||||
* An ApplicationListener to load config beans
|
||||
*/
|
||||
|
|
@ -53,11 +54,15 @@ public class DubboConfigApplicationListener implements ApplicationListener<Dubbo
|
|||
@Override
|
||||
public void onApplicationEvent(DubboConfigInitEvent event) {
|
||||
if (nullSafeEquals(applicationContext, event.getSource())) {
|
||||
// It's expected to be notified at org.springframework.context.support.AbstractApplicationContext.registerListeners(),
|
||||
// before loading non-lazy singleton beans. At this moment, all BeanFactoryPostProcessor have been processed,
|
||||
if (initialized.compareAndSet(false, true)) {
|
||||
initDubboConfigBeans();
|
||||
}
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
// It's expected to be notified at org.springframework.context.support.AbstractApplicationContext.registerListeners(),
|
||||
// before loading non-lazy singleton beans. At this moment, all BeanFactoryPostProcessor have been processed,
|
||||
if (initialized.compareAndSet(false, true)) {
|
||||
initDubboConfigBeans();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ public class ReferenceBeanManager implements ApplicationContextAware {
|
|||
* @param referenceBean
|
||||
* @throws Exception
|
||||
*/
|
||||
private synchronized void initReferenceBean(ReferenceBean referenceBean) throws Exception {
|
||||
public synchronized void initReferenceBean(ReferenceBean referenceBean) throws Exception {
|
||||
|
||||
if (referenceBean.getReferenceConfig() != null) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in New Issue