10 Replies Latest reply on Dec 4, 2007 6:04 AM by ktalasu

    HELP: javax.naming.NameNotFoundException: comp not bound

    cnbs

      Can't get java:comp namespace on JBoss 4.0.4
      My application deploys without any exceptions, but its own namespace isn't created.
      When i try to execute something like this :

      ctx.lookup("java:comp/env/..");

      i get this:
      javax.naming.NameNotFoundException: comp not bound


      What can i try to do with this?

      This is my JNDIView list() output:
      java: Namespace
      
       +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
       +- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
       +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
       +- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
       +- comp (class: javax.naming.Context)
       +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
       +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
       +- jaas (class: javax.naming.Context)
       | +- other (class: org.jboss.security.plugins.SecurityDomainContext)
       | +- JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext)
       | +- jbossmq (class: org.jboss.security.plugins.SecurityDomainContext)
       | +- HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext)
       +- timedCacheFactory (class: javax.naming.Context)
      Failed to lookup: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy
       +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
       +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
       +- Mail (class: javax.mail.Session)
       +- comp.ejb3 (class: javax.naming.Context)
       | NonContext: null
       +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
       +- TransactionManager (class: org.jboss.tm.TxManager)
      
      
      Global JNDI Namespace
      
       +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
       +- TopicConnectionFactory (class: org.jboss.naming.LinkRefPair)
       +- EventDispatcher (class: org.jboss.ws.eventing.mgmt.DispatcherDelegate)
       +- UserTransactionSessionFactory (proxy: $Proxy35 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
       +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
       +- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
       +- QueueConnectionFactory (class: org.jboss.naming.LinkRefPair)
       +- topic (class: org.jnp.interfaces.NamingContext)
       | +- testDurableTopic (class: org.jboss.mq.SpyTopic)
       | +- testTopic (class: org.jboss.mq.SpyTopic)
       | +- securedTopic (class: org.jboss.mq.SpyTopic)
       +- queue (class: org.jnp.interfaces.NamingContext)
       | +- A (class: org.jboss.mq.SpyQueue)
       | +- testQueue (class: org.jboss.mq.SpyQueue)
       | +- ex (class: org.jboss.mq.SpyQueue)
       | +- DLQ (class: org.jboss.mq.SpyQueue)
       | +- D (class: org.jboss.mq.SpyQueue)
       | +- C (class: org.jboss.mq.SpyQueue)
       | +- B (class: org.jboss.mq.SpyQueue)
       +- myApp-ear (class: org.jnp.interfaces.NamingContext)
       | +- MyFirstBean (class: org.jnp.interfaces.NamingContext)
       | | +- remote (proxy: $Proxy78 implements interface MyFirstRemote,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)
       | +- MySecondBean (class: org.jnp.interfaces.NamingContext)
       | | +- remote (proxy: $Proxy67 implements interface MySecondRemote,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)
       +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
       +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
       +- jmx (class: org.jnp.interfaces.NamingContext)
       | +- invoker (class: org.jnp.interfaces.NamingContext)
       | | +- RMIAdaptor (proxy: $Proxy34 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
       | +- rmi (class: org.jnp.interfaces.NamingContext)
       | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
       +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
       +- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
      










        • 1. Re: HELP: javax.naming.NameNotFoundException: comp not bound
          peterj

          Use ctx.lookup("myApp-ear/MyFirstBean/remote");

          • 2. Re: HELP: javax.naming.NameNotFoundException: comp not bound
            cnbs2

             

            "PeterJ" wrote:
            Use ctx.lookup("myApp-ear/MyFirstBean/remote");

            Thank you PeterJ..
            I forgot to say that i need an TimerService or EJBContext or SessionContext.. How to get a remote i know :)

            • 3. Re: HELP: javax.naming.NameNotFoundException: comp not bound
              cnbs

              I just need something like this:

              
              Ejb Module: MyAppEJB.jar
              
              
               java:comp namespace of the MyBean bean
               :
               +- env (class: org.jnp.interfaces.NamingContext)
              
              
              java: Namespace
              +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
               +- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
               +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
               +- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
               +- comp (class: javax.naming.Context)
               +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
               +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
               +- jaas (class: javax.naming.Context)
              ............
              
              


              help please..

              • 4. Re: HELP: javax.naming.NameNotFoundException: comp not bound
                jaikiran

                If thats what you want to have, then you will have to specify an env-entry for your bean. Have a look at the dtd of ejb-jar.xml at:
                http://java.sun.com/dtd/ejb-jar_2_0.dtd

                Here's an extract:


                <!--
                The env-entry element contains the declaration of an enterprise bean's
                environment entry. The declaration consists of an optional
                description, the name of the environment entry, and an optional
                value. If a value is not specified, one must be supplied
                during deployment.

                Used in: entity, message-driven, session
                -->
                <!ELEMENT env-entry (description?, env-entry-name, env-entry-type,
                env-entry-value?)>

                <!--
                The env-entry-name element contains the name of an enterprise bean's
                environment entry. The name is a JNDI name relative to the
                java:comp/env context
                . The name must be unique within an enterprise bean.

                Used in: env-entry

                Example:

                <env-entry-name>minAmount</env-entry-name>
                -->
                <!ELEMENT env-entry-name (#PCDATA)>

                <!--
                The env-entry-type element contains the fully-qualified Java type of
                the environment entry value that is expected by the enterprise bean's
                code.

                The following are the legal values of env-entry-type:

                java.lang.Boolean
                java.lang.Byte
                java.lang.Character
                java.lang.String
                java.lang.Short
                java.lang.Integer
                java.lang.Long
                java.lang.Float
                java.lang.Double


                Used in: env-entry

                Example:

                <env-entry-type>java.lang.Boolean</env-entry-type>
                -->
                <!ELEMENT env-entry-type (#PCDATA)>

                <!--
                The env-entry-value element contains the value of an enterprise bean's
                environment entry. The value must be a String that is valid for the
                constructor of the specified type that takes a single String
                parameter, or for java.lang.Character, a single character.

                Used in: env-entry

                Example:

                <env-entry-value>100.00</env-entry-value>
                -->
                <!ELEMENT env-entry-value (#PCDATA)>


                • 5. Re: HELP: javax.naming.NameNotFoundException: comp not bound
                  cnbs

                   

                  "jaikiran" wrote:
                  If thats what you want to have, then you will have to specify an env-entry for your bean. Have a look at the dtd of ejb-jar.xml at:
                  http://java.sun.com/dtd/ejb-jar_2_0.dtd

                  Here's an extract:



                  Thank you.. but I need an ejb ENC context, from where i want to get EJBContex, TimerService..
                  I want to know, is this ENC context is created by JBoss automatically during deployment, or i must somehow set it by myself?
                  And annotations like @Resource, @EJB, @TimerService are not working to. I just can't do anything.
                  And, do i need ejb-jar.xml or jboss.xml?

                  • 6. Re: HELP: javax.naming.NameNotFoundException: comp not bound
                    cnbs

                     

                    The env-entry-name element contains the name of an enterprise bean's
                    environment entry. The name is a JNDI name relative to the
                    java:comp/env context

                    I don't have this "java:comp/env" context to which all my environment resources names (like env-entry) have to be relative.

                    • 7. Re: HELP: javax.naming.NameNotFoundException: comp not bound
                      ashahashah

                       

                      "cnbs" wrote:
                      The env-entry-name element contains the name of an enterprise bean's
                      environment entry. The name is a JNDI name relative to the
                      java:comp/env context

                      I don't have this "java:comp/env" context to which all my environment resources names (like env-entry) have to be relative.


                      Did you resolve this issue? Are you using EJB3.0? If you are then using the DTD http://java.sun.com/dtd/ejb-jar_2_0.dtd will do you no good. You have to use the ejb_3_0.xsd. Also, if you want to do a new InitialContext().lookup() for an env-entry from your deployment descriptor using JBoss 4.0.4GA and EJB3, then you have to use java:comp.ejb3/env/... and not just java:comp/env/...

                      • 8. Re: HELP: javax.naming.NameNotFoundException: comp not bound
                        cnbs

                         

                        "ashahashah" wrote:
                        "cnbs" wrote:
                        The env-entry-name element contains the name of an enterprise bean's
                        environment entry. The name is a JNDI name relative to the
                        java:comp/env context

                        I don't have this "java:comp/env" context to which all my environment resources names (like env-entry) have to be relative.


                        Did you resolve this issue? Are you using EJB3.0? If you are then using the DTD http://java.sun.com/dtd/ejb-jar_2_0.dtd will do you no good. You have to use the ejb_3_0.xsd. Also, if you want to do a new InitialContext().lookup() for an env-entry from your deployment descriptor using JBoss 4.0.4GA and EJB3, then you have to use java:comp.ejb3/env/... and not just java:comp/env/...


                        No i didn't resolve it yet.
                        Yes i'm using EJB3.0 And using ejb_3_0.xsd. But this creates another error which is described here:
                        http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3964529#3964529
                        But i have a question - do i have to deploy with ejb-jar.xml or Jboss should create ENC environment from my metadata annotations?

                        And about java:comp.ejb3/env/.. i know that i should use it and i did so. And as you can see both of this context are empty:

                        +- comp (class: javax.naming.Context)
                        ...
                        +- comp.ejb3 (class: javax.naming.Context)
                        | NonContext: null

                        • 9. Re: HELP: javax.naming.NameNotFoundException: comp not bound
                          cnbs

                          I just resolve it. :)
                          Not the "comp not bound" but the "@Resource and @TimerService not working" problem.
                          I always tried to work with TimerService or SessionContex in a constructor and got the NPE. All i had to do is to try this in a method not in the constructor :)


                          • 10. javax.naming.NameNotFoundException: comp not bound
                            ktalasu

                            javax.naming.NameNotFoundException: comp not bound any solution? i