Results 1 to 6 of 6

Thread: Dynamically adding a bean to the ApplicationContext

  1. #1

    Default Dynamically adding a bean to the ApplicationContext

    Is it possible to dynamically add a bean to the application context? My application has to support registration of XTensions at run time. My limited knowledge of Spring says that only those beans are registered with application context which are defined in the context (XML) file. Suppose a new bean is available for service (may be on separate machine). How can I register this new bean with my application context?
    My requirement could be analogous to adding a new bean tag in the context file at run time.
    Thanks,
    Kapil

  2. #2
    Join Date
    Aug 2004
    Location
    u.s.a
    Posts
    399

    Default

    Please see this thread which shows how to use the ConfigurableApplicationContext:

    http://forum.springframework.org/sho...getBeanFactory

  3. #3

    Default

    I tried to register my bean using registerBeanDefinition API but received following error on calling the getBean API of the applicationContext.

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'testService' defined in null:
    Instantiation of bean failed; nested exception is java.lang.SecurityException: Can not make a java.lang.Class constructor accessible
    java.lang.SecurityException: Can not make a java.lang.Class constructor accessible

    Please help,
    Kapil

  4. #4

    Default

    Finally am able to dynamically register bean at runtime. I was making the mistake of passing object instead of Class object to the RootBeanDefinition constructor.

    The dynamic registration worked for the beans in the same JVM.
    Is it possible to register a bean running in separate JVM?

  5. #5
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    it depends on what exactly are your requirements. If you have the 'connection' mechanism in place and you can work with the remote application context you can do also registration. However, Spring doesn't has support for clustered or distributed application context. There are some products out there that add such functionality but most of them are commercial.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  6. #6

    Default

    I was able to register bean running on different JVM using the same approach of using registerBeanDefinition() api and specifying the property values for serviceURL and interface in the RootBeanDefinition object.

    While creating rmi proxy, why can't a bean specify more than one interface in the serviceInterface property? Actually my class is implementing two interfaces and I want to typecast it on client side in one of the two interfaces depending on some condition.
    Thanks,
    Kapil

Posting Permissions

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