apache/dubbo · error · ScopeBeanException

register bean failed! name=${name}, type=${className}

Error message

register bean failed! name=${name}, type=${className}

What it means

Thrown by ScopeBeanFactory.registerBean(String, Object) during the post-registration lifecycle: setting the ExtensionAccessor, running all ExtensionPostProcessors, and calling Initializable.initialize(). If any of those steps throws, the whole registration is aborted and the cause is chained. The bean was constructed but failed to be wired/initialized.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/beans/factory/ScopeBeanFactory.java:206

            }
        }
        return bean;
    }

    private void initializeBean(String name, Object bean) {
        checkDestroyed();
        try {
            if (bean instanceof ExtensionAccessorAware) {
                ((ExtensionAccessorAware) bean).setExtensionAccessor(extensionAccessor);
            }
            for (ExtensionPostProcessor processor : extensionPostProcessors) {
                processor.postProcessAfterInitialization(bean, name);
            }
            if (bean instanceof Initializable) {
                ((Initializable) bean).initialize(extensionAccessor);
            }
        } catch (Exception e) {
            throw new ScopeBeanException(
                    "register bean failed! name=" + name + ", type="
                            + bean.getClass().getName(),
                    e);
        }
    }

    @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
    private void initializeBeanDefinitions(Class<?> type) {
        for (int i = 0, size = registeredBeanDefinitions.size(); i < size; i++) {
            BeanDefinition<?> definition = registeredBeanDefinitions.get(i);
            if (definition.initialized) {
                continue;
            }

            Class<?> beanClass = definition.beanClass;
            if (!type.isAssignableFrom(beanClass)) {
                continue;
            }

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Inspect the chained cause to identify whether a post-processor or Initializable.initialize() failed.
  2. Fix the failing initialize()/post-processor logic so it does not throw during registration.
  3. Ensure required extensions/beans the initializer depends on are registered before this bean.
  4. If using a custom ExtensionPostProcessor, make it defensive (skip beans it does not own) so it cannot break unrelated registrations.

Example fix

// before
public class MyBean implements Initializable {
    public void initialize(ExtensionAccessor a) {
        this.dep = a.getExtension(Dep.class);  // throws if Dep missing
    }
}
// after
public class MyBean implements Initializable {
    public void initialize(ExtensionAccessor a) {
        this.dep = Objects.requireNonNull(a.getExtension(Dep.class), "Dep extension required");
    }
}
// and ensure Dep SPI is on the classpath before registering MyBean
Defensive patterns

Strategy: try-catch

Try / catch

try {
    factory.registerBean(name, bean);
} catch (ScopeBeanException e) {
    Throwable cause = e.getCause();
    // cause originates from a post-processor or Initializable.initialize(); fix that path
    log.error("Bean {} failed wiring/initialize", name, cause);
}

Prevention

When it happens

Trigger: registerBean(name, instance) where the instance is ExtensionAccessorAware, or any registered ExtensionPostProcessor throws in postProcessAfterInitialization, or the bean implements Initializable and its initialize() throws.

Common situations: A bean's initialize() depends on an extension not yet loaded; a custom ExtensionPostProcessor fails on a specific bean; bean implements ExtensionAccessorAware and misuses the accessor; post-processor ordering changed after a Dubbo version upgrade.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/1bae4c10b411893a. Report an issue: GitHub.