Version 6

    Why do I get NameNotFoundException?

     

    By default JBoss binds ConnectionFactorys/[DataSource|DataSource]s in the java: namespace. This is only visible inside the same virtual machine and only when using a naming context that is not configured to use a transport.

     

    Mistake 1 - Not using the java: namespace

    <local-tx-datasource> 
      <jndi-name>GenericDS</jndi-name> 
      <connection-url>[jdbc: url for use with Driver class]</connection-url> 
      <driver-class>[fully qualified class name of java.sql.Driver implementation]</driver-class> 
      <user-name>x</user-name> 
      <password>y</password> 
    </local-tx-datasource>
    

     

    WRONG!

    new InitialContext().lookup("GenericDS");
    

     

    CORRECT

    new InitialContext().lookup("java:/GenericDS");
    

     

    Mistake 2 - Going over a transport

     

    By using a provider url, you are effectively make your jndi access remote,

    meaning the java: namespace is not visible.

    Properties props = new Properties();
    ...
    props.put(javax.naming.Context.PROVIDER_URL,"jnp://localhost:1099");
    IntialContext context = new InitialContext(props)
    

     

    use-java-context

     

    In JBoss4 you can bind the DataSource in the global namespace

    <local-tx-datasource> 
      <jndi-name>GenericDS</jndi-name>
      <use-java-context>false</use-java-context>
      <connection-url>[jdbc: url for use with Driver class]</connection-url> 
      <driver-class>[fully qualified class name of java.sql.Driver implementation]</driver-class> 
      <user-name>x</user-name> 
      <password>y</password> 
    </local-tx-datasource>
    

     

    Related