Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-2336

@Resource annotation not used with beans defined by id

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • 2.0.11
    • None
    • Plugin - Spring
    • None
    • spring 2.5, tomcat 6, java se 1.5, eclipse 3.3.0

    Description

      There seems to be a problem with the spring interaction.

      Consider the following scenario :

      A action class using the @Resource annotation :
      public class ListValuableAction {
      @Resource
      private StockManager stockManager;

      They are mapped in the applicationContext.xml as beans :
      <bean id="listValuableAction" scope="prototype" class="gestion.view.actions.ListValuableAction"/>
      <bean id="stockManager" class="capitalism.dao.StockManager"/>

      In the struts.xml I have:
      <action name="*" class="capitalism.view.actions.

      {1}Action" >
      <result>/WEB-INF/views/{1}

      .jsp</result>
      </action>

      <action name="toto" class="listValuableAction" >
      <result>/WEB-INF/views/ListValuable.jsp</result>
      </action>

      The first action works fine, the stockManager bean is set in the ListValuableAction instance.
      The second does not work. The stockManager bean is NOT set in the ListValuableAction instance.

      I try to play with scope="prototype", removing it. Does the same.
      My unit tests complete fine using the bean listValuableAction, the stockManager field is always set, so i'm quite sure is not a problem with Spring.

      If I inject in the applicationContext.xml :
      <bean id="listValuableAction" scope="prototype" class="capitalism.view.actions.ListValuableAction">
      <property name="stockManager" ref="stockManager"/>
      </bean>
      it works.

      In conclusion the problem arise only when using a bean declared by id which use the @Resource annotation.
      Using @Resource in a bean declared by class name works.
      Using a bean declared by id which injections are in the applicationContext.xml works.

      Hope it helps.

      PS : Sorry if my English is a little poor.

      Attachments

        Activity

          People

            lukaszlenart Lukasz Lenart
            jester Sébastien Derivaux
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: