Uploaded image for project: 'EJB 3.0'
  1. EJB 3.0
  2. EJBTHREE-958

@Resource annotation's element "name" does not default to field name.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Minor Minor
    • AS 5.0.0.Beta3
    • AS 4.2.0 GA
    • EJB3 Extensions
    • None
    • Workaround Exists
    • Hide

      To use version 2.

      Show
      To use version 2.
    • Low

      The javadoc of @Resource#name states that "The JNDI name of the resource. For field annotations, the default is the field name. ..."

      The following version 1 of DaServiceBean don't work as it doesn't inject anything to "myVar". The version 2 injects the value 5 correctly.

      — Version 1 —
      @Stateless
      @Remote
      @RemoteBinding(jndiBinding="daService")
      public class DaServiceBean implements DaService {
      @Resource private int myVar;
      public void foo()

      { System.out.println("myVar: " + myVar); }

      }

      — Version 2 —
      @Stateless
      @Remote
      @RemoteBinding(jndiBinding="daService")
      public class DaServiceBean implements DaService {
      @Resource(name="myVar") private int myVar;
      public void foo()

      { System.out.println("myVar: " + myVar); }

      }

      — ejb-jar.xml —
      <enterprise-beans>
      <session>
      <ejb-name>DaServiceBean</ejb-name>
      <env-entry>
      <env-entry-name>myVar</env-entry-name>
      <env-entry-type>java.lang.Integer</env-entry-type>
      <env-entry-value>5</env-entry-value>
      </env-entry>
      </session>
      </enterprise-beans>

              arubinge@redhat.com Andrew Rubinger (Inactive)
              nyri_jira Jari Mustonen (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Estimated:
                  Original Estimate - 1 hour
                  1h
                  Remaining:
                  Remaining Estimate - 1 hour
                  1h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified