DEV Community

Query Filter
Query Filter

Posted on

docker-163

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.FileSystemResource;
import java.io.File;
import java.util.List;

private void parseSpringConfigFiles(List<File> springConfigFiles) {
    for (File springConfigFile : springConfigFiles) {

        // 1. Initialize the modern empty Spring registry container
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

        // 2. Bind the XML Definition Reader strategy to the container
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);

        // 3. Populate the container by reading the legacy XML file
        reader.loadBeanDefinitions(new FileSystemResource(springConfigFile));

        // --- Core parsing and namespace calculation logic remains identical ---
        String fileName = springConfigFile.getName();
        String prefix = "spring-";
        String suffix = ".xml";

        String name = fileName.substring(prefix.length(), fileName.length() - suffix.length());
        String namespace = name.replaceAll("-", "/");

        this.logger.debug("Adding bean factory for namespace: '" + namespace + "'");

        // 4. Cache the populated factory instance into your map
        this.beanFactories.put(namespace, beanFactory);
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)