DEV Community

Query Filter
Query Filter

Posted on

docker-165

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

private DefaultListableBeanFactory getBeanFactory(String qualifiedBeanName) {
    int delimiterIndex = qualifiedBeanName.lastIndexOf("/");
    String namespace = "";
    if (delimiterIndex != -1) {
        namespace = qualifiedBeanName.substring(0, delimiterIndex);
    }

    // 1. Return the modern container implementation directly from your updated map field
    return this.beanFactories.get(namespace);
}

public Object getBean(String qualified_bean_name) throws ConfigurationException {
    // 2. Update local reference to our modern implementation type
    DefaultListableBeanFactory beanFactory = this.getBeanFactory(qualified_bean_name);

    if (beanFactory == null) {
        this.logger.warn("Could NOT retrieve bean with name: '" + qualified_bean_name + "' because the namespace could not be resolved");
        return null;
    } else {
        String beanName = qualified_bean_name.substring(qualified_bean_name.lastIndexOf("/") + 1);

        try {
            // 3. This stays identical because DefaultListableBeanFactory fulfills standard IoC lookup contracts
            return beanFactory.getBean(beanName);
        } catch (Exception e) {
            throw new ConfigurationException("There was an error retrieving bean: '" + beanName + "' with qualified name: '" + qualified_bean_name + "'", e);
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)