Announcement Announcement Module
Collapse
No announcement yet.
Why dynamic language bean scope must be "singleton" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Why dynamic language bean scope must be "singleton"

    In the current springframework dynamic language support, all scripting bean scope is restricted to "singleton". But the 'singleton" scope restrict all scripting bean usage. For example:
    ...
    Person person1 = context.getBean("GroovyPerson") ;
    person.setName("chris tam") ;
    Person person2 = context.getBean("GroovyPerson") ;
    person2.setName("rod johnson") ;
    ...
    // print "rod johnson" rather than "chris tam"
    System.out.println(person1.getName());
    ...
    Is there any special reason that dynamic language support must be "singleton"? I had asked the same question in the core forum but nobody give an answer. I am sorry to repost this question again in this forum. Thanks a lot for any comment or answer.

    chris tam
    xenium

  • #2
    Hi,
    please look at the documentation:
    http://static.springframework.org/sp...factory-scopes

    There is why. You can define any scope you want for differnet reasons.

    Antoni

    Comment


    • #3
      I am sorry that my question may be confusing. "scope" attribute is not allowed in dynamic language support. For example, the following bean definition is not allowed in application context xml file:
      ...
      <lang:groovy id="GroovyPerson"
      script-source="classpath: org/test/GroovyPerson.groovy"
      scope="prototype"/>
      ...
      The spring-lang-2.0.xsd does not allowed the attribute "scope" or "script-scope" in lang:groovy. I have checked the spring-lang-2.0.xsd file and ScriptBeanDefinitionParser file. The scripting bean "scope" is always "singleton" and there is no way to set the "scope" attribute for any scripting bean in the application context xml file. Are there any hidden problems if it is allowed to set the scripting bean scope in application context xml file? Thanks a lot for any help.

      chris tam
      xenium

      Comment


      • #4
        Hi Chris,
        Is your problem solved. I mean is there any update from spring Team providing scope="prototype" support for groovy bean.
        Last edited by shivnarayan; Mar 22nd, 2007, 12:58 AM. Reason: typo error

        Comment


        • #5
          Dear shivnarayan

          The problem is already fixed in the 2.0.4 snapshot. The attribute "scope" is added for scripting bean. You can download the 2.0.4 snapshot and test it.

          cheers
          chris tam
          xenium

          Comment


          • #6
            Yes, It is working for me also.

            Comment

            Working...
            X