Results 1 to 3 of 3

Thread: MAnually loading the Bean Confgs

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    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.

  3. #3
    Join Date
    Sep 2004
    Posts
    17

    Default

    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.

Similar Threads

  1. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  2. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  3. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •