0

We were using 4.2.x version of spring and we are using BeanFactoryLocator to create a factory from xml file.

method to return Beanfactory:

private BeanFactory createServicesContainer() {
        BeanFactoryLocator bfLocator = SingletonBeanFactoryLocator.getInstance("Connector.xml");
        BeanFactoryReference bfReference = bfLocator.useBeanFactory("bigBean");
        return bfReference.getFactory();
    }

my Connector.xml file contains:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
       default-lazy-init="false">

    <!--
        The Big Bean for accessing all the repository services. This factory bean serves as
        and umbrella bean for all the underlying repository services.
    -->
    <bean id="bigBean" class="org.springframework.context.support.ClassPathXmlApplicationContext">
        <constructor-arg>
            <list>
                <value>sample1-connector.xml</value>
                <value>sample2-connector.xml</value>
                <value>sample3-connector.xml</value>
            </list>
        </constructor-arg>
    </bean>
</beans>

Now how can make changes it to work in Spring 5.x

Bharath
  • 81
  • 1
  • 11
  • Load the files from `bigBean` into your context instead of the `beanRefFactory` thing. – M. Deinum Mar 08 '22 at 08:17
  • BeanFactory factory = new ClassPathXmlApplicationContext("Connector.xml"); BeanFactory fs=(BeanFactory) factory.getBean("bigBean"); return fs; will these works? – Bharath Mar 08 '22 at 08:27
  • Just ditch that file and just load the `sample1-connector.xml` etc. directly with your `ContextLoaderListener` or use `` in an xml file to get these loaded to (you could change your `beanRefContext.xml` to that and let the `ContextLoaderListener` load that file. – M. Deinum Mar 08 '22 at 08:31
  • i didn't get could you please give me an example – Bharath Mar 08 '22 at 08:40
  • The example is in the comments. Replace what you have now in your `beanRefContext.xml` with ` – M. Deinum Mar 08 '22 at 08:45
  • i think ContextLoaderListener is used in web.xml to automate the creation of the ApplicationContext where we need to specify multiple xml files under contextconfigloaciton, is this correct..... but here i need to create applicationContext/Beanfactory in a method and return to caller.. – Bharath Mar 08 '22 at 10:05
  • Why? That seems very inefficient as it will recreate things each time. I would no mark this question to be closed as apparently there is more information needed to help you. You haven't included all the details in here. – M. Deinum Mar 08 '22 at 10:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/242723/discussion-between-bharath-and-m-deinum). – Bharath Mar 08 '22 at 12:34
  • Someone solved it like [this](https://stackoverflow.com/questions/46902115/spring-framework-5-0-0-final-parent-context-not-getting-loaded/70094114#70094114) – Lonzak Apr 07 '22 at 15:43

0 Answers0