Announcement Announcement Module
Collapse
No announcement yet.
New bean for every session Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • New bean for every session

    Hello!
    I have probably stupid question but I do not found answer in the web.

    I need to implement spring bean that will leave only in one session - so, new object will be created for every new session.

    I think it is not a problem to implement it in my own Bean Factory that will acts as singlet, but will contain map for session - object - so, for every session will be used own object, but probably some solution already exists in Spring Core.

    So, may somebody advice anything about this issue?
    Thank you!

  • #2
    Get Factory instead of Bean

    Hello!
    Another stupid question:

    I have beans like:
    Code:
    <bean id="beanA" class="ClassB">
      <property name="prop1" ref="beanB"/>
    </bean>
    
    <bean id="beanB" class="BeanBFactory">
    </bean>
    For so, beanA expects classA in getProp1
    For beanB I have singleton BeanFactory (BeanBFactory) used for making beanB

    So, by default beanB created then application is initialized and tried to set beanB to beanA.

    But I need to create beanB only then it is really started to be used in beanA - not during application start, but during user working...

    In this case I should set into beanA not beanB - but it's factory - to create object via it then it is required.

    OK, I changed ClassA::setProp1 so, it expects BeanBFactory - but still beanB is created during application initialization

    And only if I remove
    Code:
    implements BeanFactory
    from my BeanBFactory everything started to work.

    So, is it correct solution, or there are some standard pattern exists in Spring for such cases?

    Thank you for any advice

    Comment


    • #3
      Uups, second post I moved to separate thread

      Uups, second post I moved to separate thread

      Comment


      • #4
        Maybe you should wait for Spring 2.0RC1 as there is support for bean scoping. The RC1 documentation should also contain information about this.
        RC1 should be available this month. If it's urgent you could also get a nightbuild from CVS.

        Regards,
        Andreas

        Comment


        • #5
          Nice to hear

          It is nice to hear and nice to get so fast answer!
          Thank you.

          No, it is not very urgent - anyway I can use some workaround until normal solution from Spring will not be ready

          Comment


          • #6
            Session scoped Bean

            Hello! As I found from 2.0-M5 session scoped bean are supported by Spring, but in chapter 4.2.5 of Spring Reference still information about only singleton-not singleton.

            There I can find information about how to create session scoped bean?

            Comment


            • #7
              Hi Alexey

              Please do accept my apologies about the lack of documentation surrounding the new scoping support in Spring. The aforementioned scoping support is (or rather was) one of the last things to be finalised for Spring 2.0, and as such I have been waiting for the dust to settle before documenting it.

              If you watch the following JIRA issue you will be able to see when I have finished and committed the documentation.

              http://opensource.atlassian.com/proj...rowse/SPR-1850

              Spring 2.0 is going to be final (famous last words) in time for the SpringOne conference next week, so come hell or high water the docs will be done by then at the very latest. So only a week and a bit to go max

              Cheers
              Rick

              Comment


              • #8
                Originally posted by akakunin
                Hello!
                Another stupid question:

                I have beans like:
                Code:
                <bean id="beanA" class="ClassB">
                  <property name="prop1" ref="beanB"/>
                </bean>
                
                <bean id="beanB" class="BeanBFactory">
                </bean>
                For so, beanA expects classA in getProp1
                For beanB I have singleton BeanFactory (BeanBFactory) used for making beanB

                So, by default beanB created then application is initialized and tried to set beanB to beanA.

                But I need to create beanB only then it is really started to be used in beanA - not during application start, but during user working...

                In this case I should set into beanA not beanB - but it's factory - to create object via it then it is required.

                OK, I changed ClassA::setProp1 so, it expects BeanBFactory - but still beanB is created during application initialization

                And only if I remove
                Code:
                implements BeanFactory
                from my BeanBFactory everything started to work.
                Unsure here, but you may want to look at the FactoryBean[1], and search the web for examples of it.

                [1] http://static.springframework.org/sp...le-factorybean

                Comment


                • #9
                  OK, I found how it work

                  Rick, no problem
                  I already found how it works and during testing found a problem:
                  http://opensource.atlassian.com/proj...rowse/SPR-2105

                  But problem not very difficult, so, after fixding it everything work perfect!

                  Thank you for your job!

                  Comment

                  Working...
                  X