Announcement Announcement Module
Collapse
No announcement yet.
injecting properties in prototype bean (using 2.0 RC3) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • injecting properties in prototype bean (using 2.0 RC3)

    Hello,

    I observe a strange behavior and I cannot figure out why:
    I can inject ref pointing to other bean in my bean (singleton="false") but I cannot inject properties (such as simple String).
    In my applicationcontext.xml I have something like this:

    <property name="userManager" ref="userManager"/>
    <property name="roleManager" ref="roleManager"/>
    <property name="imageCaptchaService" ref="imageCaptchaService"/>
    <property name="javaMailSender" ref="javaMailSender"/>
    <property name="velocityEngine" ref="velocityEngine"/>
    <property name="emailBodyTemplateName" value="signup.email"/>
    <property name="roles" value="ROLE_USER,ROLE_ADMIN,ROLE_DUMMY"/>

    all the ref are set correctly, but the values are not!


    Regards,
    Nicolas.

  • #2
    Are you saying that with singleton="true" the properties are injected? I find that very hard to understand, so no idea what's going on if true.

    Just out of interest, why do you need singleton="false" for this bean (there are no details here, but I can't think why a service for sending e-mails would need to be a prototype bean)?

    Comment


    • #3
      The bean is a webwork "action" that process user registration (actions in webwork are not singleton)

      I tried different combination (including to make it singleton), but it did not help.

      I realize the behavior is weird, so I must be missing something.

      Comment


      • #4
        This is now slightly off topic, but the Spring lifecycle is independent of the implementation of your beans themselves. So even if the bean is not a "classic" singleton, it can be a Spring singleton (and usually service classes like this one are). Probably doesn't make much difference in practice, because often they are only instantiated once anyway, but it's better style to use the default lifecycle unless you have a good reason not to.

        Comment


        • #5
          Are you using the xwork-optional package? It provides nice integration between Spring and WebWork.
          How are you properties which you try to insert as values declared? There might some type conversion going on which results in the null value.

          Comment


          • #6
            Hi,

            I think I found my problem...
            I declared my action bean in a regular application context spring file.
            And I also declared in xwork.xml the action as follow

            <action name="register" class="com.acme.webaction.RegisterAction" method="register">
            <interceptor-ref name="validationWorkflowStack"/>
            <result name="success">/</result>
            <result name="input">/signup/register.jsp</result>
            <result name="error">/signup/register.jsp</result>
            </action>

            I should have set the class attribute to the bean name declared in the application context... as explained here:
            http://www.opensymphony.com/webwork/...cs/Spring.html

            basically the action was not instanciated using the spring application context file but using the xwork config ==> my properties were not set... Note that the bean ref (that are absent above) were set thanks to the auto wiring mode

            My conclusion (beside that I should have read more carefuly the manual) is that xwork config could be enhanced by providing a ref attribute to make things more obvious. I'll try to find some time to send a patch to ww team.

            Thanks for your help and this amazing framework.

            Nicolas

            Comment

            Working...
            X