6 Replies Latest reply on Mar 26, 2007 11:01 AM by holeinone

    Problem with @Resource and JBOSS

    tamri

      I have a sessionBean and a call a datasource so
      @Resource
      public DataSource myDB;
      when I run a jboss (jboss-4.0.4.CR2) it thows exception :

      java.lang.RuntimeException: You did not specify a @Resource.mappedName() on publ
      ic javax.sql.DataSource svr.SessionItemInfoBean.datasource and there is no bindi
      ng for that enc name in XML.

      after that I write @Resource(mappedName="DS"), this code shows that @Resource has't attribute mappedName.

      What can I do? I want to use @Resource to inject
      DataSource . Enyone knows how can I do?

        • 1. Re: Problem with @Resource and JBOSS
          anders.hedstrom

          Try

          @Resource(mappedName="java:<your-jndi-name>")
          protected DataSource ds;


          • 2. Re: Problem with @Resource and JBOSS
            tamri

             

            "anders.hedstrom" wrote:
            Try

            @Resource(mappedName="java:<your-jndi-name>")
            protected DataSource ds;


            I have tryed, bat it is error "mappedName not found"

            • 3. Re: Problem with @Resource and JBOSS
              anders.hedstrom

              Are you sure your using the correct jndi name?

              I'm using jboss-4.0.4.CR2 as well, and here's how I do it:

              I got the following line in my -ds.xml file:

              <datasources>
               <local-tx-datasource>
               <jndi-name>jdbc/MyDS</jndi-name>
              ...
              


              and I got the following code in my EJB;

              @Resource(mappedName="java:jdbc/MyDS")
              protected DataSource ds;


              And it works fine...

              • 4. Re: Problem with @Resource and JBOSS
                anders.hedstrom

                Are you sure your using the correct jndi name?

                I'm using jboss-4.0.4.CR2 as well, and here's how I do it:

                I got the following line in my -ds.xml file:

                <datasources>
                 <local-tx-datasource>
                 <jndi-name>jdbc/MyDS</jndi-name>
                ...
                


                and I got the following code in my EJB;

                @Resource(mappedName="java:jdbc/MyDS")
                protected DataSource ds;


                And it works fine...

                • 5. Re: Problem with @Resource and JBOSS
                  tamri

                  I have so in -ds.xml

                  <local-tx-datasource>
                  <jndi-name>jdbc/MSSQLDS</jndi-name>

                  and
                  @Resource(mappedName="java:jdbc/MSSQLDS") protected DataSource ds;

                  you see it is the same, what you has written, bat I don't understand why is error on keywords "mappedName "

                  • 6. Re: Problem with @Resource and JBOSS
                    holeinone

                    instead of mappedName try just "name" for instance:

                    @Resource(name="java:/QueueConnectionFactory")
                    private javax.jms.QueueConnectionFactory connectionFactory;