Results 1 to 2 of 2

Thread: Deferring class instantiation until first use

  1. #1
    Join Date
    Dec 2004
    Posts
    2

    Default Deferring class instantiation until first use

    It appears as if Spring instantiates a class when a configuration file is loaded instead of deferring to first use of that bean, regardless of whether the lazy-init parameter has been set to true. It throws a "ClassNotFoundException".

    Is there any way to defer the instantiation of the class until first use?

    We are attempting to use Spring as sort of a pseudo-registry. We'd like to be able to deploy a Spring ApplicationContext xml file which has definitions for all of our Services, but allow users to only load in the particular services they need.

  2. #2
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    Instantiation of all (singleton) beans during bean factory startup is a feature of an application context, so by using a normal bean factory you should be able to avoid it.

    Another option is using prototype beans instead of singletons by setting the singleton="false" attribute on your bean definition. That way the bean factory will create a new instance of your bean every time you call getBean().

    Erwin

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Replies: 3
    Last Post: Sep 4th, 2005, 11:11 PM
  5. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM

Posting Permissions

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