Announcement Announcement Module
Collapse
No announcement yet.
MAnually loading the Bean Confgs Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MAnually loading the Bean Confgs

    Hello all,

    I am very new to the spring framework, and am currently doing an eval for my company. One of the things that I need to prove out is loading the bean config information from a Database. We have a pre built API that provides application configuration information, but I have no idea how to load a bean config manually. Any sussgestions or hints on how to accomplish this?

    For example, how can I get the equivalent of this:

    <bean id="springappController" class="web.SpringappController">
    <property name="productManager">
    <ref bean="prodMan"/>
    </property>
    </bean>

    <bean id="prodMan" class="bus.ProductManager">
    <property name="products">
    <list>
    <ref bean="product1"/>
    <ref bean="product2"/>
    <ref bean="product3"/>
    </list>
    </property>
    </bean>

    by executing code instead of having an XML file.

    Thanks!

  • #2
    HAve a look at the source code for the org.springframework.jdbc.core.support.JdbcBeanDefi nitionReader.

    BeanDefinitionReaders all provide support for reading bean definitions, based on a specified format, a database in this case. The JdbcBeanDefinitionReader isn't really sophisticated in that it doesn't support maps, lists, etcetera. But here you can see the basics.

    Furthermore, if you need to manually create a BeanFactory and bean definitions, I'd suggest you have a look at the beans.factory package and specifically the tests that test the BeanFactory. They create beans manually... But I wouldn't suggest going down that road. You're better off using the bean definition readers.

    Comment


    • #3
      You can use DefaultListableBeanFactory and RootBeanDefinition;

      DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
      RootBeanDefinition beanDef = new RootBeanDefinition(clazz, ...);
      factory.registerBeanDefinition(id, beanDef);


      However, it's rather annoying to create the entire factory in this manner. I would suggestion the previous poster's suggestion of using the JdbcBeanFactory.

      Comment

      Working...
      X