Announcement Announcement Module
Collapse
No announcement yet.
Conditionally modify bean definitions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Conditionally modify bean definitions

    Hi all,

    Spring 2.0.6 ... trying to figure out what the best course of action is here.

    Here's my usecase... I'm using WebApplicatoinContext. I've got a bunch of mapping files with a bunch of different beans.

    A new requirement has surfaced where I must make the database optional in our app. This means that all beans used for database must not be created when the db functionality is disabled. These beans are ones like DataSource, Hibernate SessionFactories, DAO's etc.

    At present I'm just using a simple boolean flag in spring to determine if the db functionality is enabled/disabled.

    Ideally I'd like to make the ApplicationContext aware of (a) this flag and (b) the db-dependent beans so that it knows not to instantiate them when the flag == false.

    Is this possible using BeanFactoryPostProcessor or BeanPostProcessor or some other way?

    I don't want to have to have a different set of mapping files and these db-references are used throughout so ideally the ApplicatoinContext would just replace all references to these beans with null.

    Any advise is much appreciated!

    Thanks,
    Shanon

  • #2
    Hi!

    I'm not sure if this is the solution to your question but you might take a look at the following thread to see if you find anything that can bring you closer to a solution there:

    http://forum.springframework.org/showthread.php?t=43549


    -Kaj

    Comment


    • #3
      Would it not be sufficient to specify for them lazy-init=true?
      If DB functionality would not be acquired by application then these beans will not be created.

      Originally posted by shanonvl View Post
      Hi all,

      Spring 2.0.6 ... trying to figure out what the best course of action is here.

      Here's my usecase... I'm using WebApplicatoinContext. I've got a bunch of mapping files with a bunch of different beans.

      A new requirement has surfaced where I must make the database optional in our app. This means that all beans used for database must not be created when the db functionality is disabled. These beans are ones like DataSource, Hibernate SessionFactories, DAO's etc.

      At present I'm just using a simple boolean flag in spring to determine if the db functionality is enabled/disabled.

      Ideally I'd like to make the ApplicationContext aware of (a) this flag and (b) the db-dependent beans so that it knows not to instantiate them when the flag == false.

      Is this possible using BeanFactoryPostProcessor or BeanPostProcessor or some other way?

      I don't want to have to have a different set of mapping files and these db-references are used throughout so ideally the ApplicatoinContext would just replace all references to these beans with null.

      Any advise is much appreciated!

      Thanks,
      Shanon

      Comment


      • #4
        Or you might need something like a LazyInitTargetSourceCreator (see javadocs) to prevent the lazy beans from being instantiated if they are not used.

        Comment

        Working...
        X