Announcement Announcement Module
No announcement yet.
How to implement a custom BeanFactory? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to implement a custom BeanFactory?

    I am developing an XML-based configuration tool called JICE that is very similar to the XmlBeanFactory of Spring Framework.

    In order to use JICE with Spring, I would like to implement a custom BeanFactory that would internally initialize beans with JICE. This would make it possible to plug JICE into Spring applications.

    what things should I consider in creating such an implementation? is it enough to just implement the BeanFactory interface? or should I implement the ApplicationContext interface?

    Information about JICE can be found at:


    Timo Laitinen

  • #2

    You should look at the BeanDefinitionReader interface rather than subclassing BeanFactory or ApplicationContext. The actual container (BeanFactory or AC) is separate from the means of configuration (BeanDefinitionReader).



    • #3
      Thank you for the quick reply! that was very fast..

      I looked at the BeanDefinitionReader briefly and it unfortenately seems to be too close to the Spring way of initializing the beans:

      - It assumes that the beans are initialized by using
      BeanDefinitionRegistry and BeanDefinition interfaces.

      - The BeanDefinition contains only the data needed (by Spring) to initialize a bean - the actual construction of a bean is done elsewhere.

      - Because the way JICE initializes objects is so different, I can't express the object creation instructions of JICE in the BeanDefinition-format.
      (If I would, all the advantages that JICE could have over Spring would be taken out..)

      I would like to find a spot that would abstract away the whole object creation process. totally JICE-based object creation could then be plugged into that "sweet spot".

      I am having a bad feeling that this won't be as easy as I hoped..

      Timo Laitinen


      • #4
        ApplicationContext & ConfigurableListableBeanFactory

        I would like to know how to get a custom BeanFactory work together with the ApplicationContext model.

        A custom BeanFactory-implementation is easy to implement, so I can easily create a JiceBeanFactory that internally uses JICE for initializing the beans.

        However, I assume that JiceBeanFactory would be usable only if it could work well together with ApplicationContext model.

        ApplicationContext-classes are themselves BeanFactories, but they probably delegate the bean initialization stuff to an internal BeanFactory-instance.

        AbstractApplicationContext for example has a method getBeanFactory() that returns the internal factory instance. subclasses specify how this factory is initialized.

        So, I could create a subclass of AbstractApplicationContext whose getBeanFactory() method would return an instance of the JiceBeanFactory.

        But there is a problem:

        AbstractApplicationContext.getBeanFactory() assumes that the factory is a ConfigurableListableBeanFactory.

        That interface requires that the BeanFactory is based on BeanDefinitions. JiceBeanFactory can't support BeanDefinitions..

        So, It seems that my choices are:

        1.) create only the JiceBeanFactory and leave it at that. JiceBeanFactory will be difficult to use because it doesn't work with the ApplicationContext model.

        2.) create a custom ApplicationContext that doesn't require ConfigurableListableBeanFactory interface. (this sounds like a lot of work.)

        My questions:

        Is there an easy way to plug a custom BeanFactory into the ApplicationContext model without implementing the ConfigurableListableBeanFactory interface?

        Is the ApplicationContext support as critical as I'm guessing? (can a custom BeanFactory be usable without ApplicationContext-support? is the alternative 1 above viable?)

        Is a custom ApplicationContext difficult to implement? (= is the alternative 2 above possible?)


        Timo Laitinen


        • #5
          'm with the same problem. Any solution?

          I want create an BeanFactory or ApplicationContext implementation that creates and returns bean proxies instead of real implementation of bean

          Victor Lindberg