You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Tom Eugelink <tb...@tbee.org> on 2017/01/16 09:13:34 UTC

Tomcat embedded context: Unable to find [java:]

Trying to launch Tomcat 8.0.39 embedded with a datasource configured, I get this error:

/Failed to log into the database: Name [java:/comp/env/myDsName] is not bound in this Context. Unable to find [java:]./

I'm configuring the default Tomcat ContactFactory. This is the relevant source:

         System.setProperty("java.naming.factory.initial", "org.apache.naming.java.javaURLContextFactory");

         StandardContext standardContext = (StandardContext)tomcat.addWebapp("/mywebapp, "/path/to/web/resources");
standardContext.getNamingResources().addResource(createJdbcResource());

         org.apache.catalina.webresources.StandardRoot standardRoot = new org.apache.catalina.webresources.StandardRoot(standardContext);
         standardContext.setResources(standardRoot);

     private static org.apache.tomcat.util.descriptor.web.ContextResource createJdbcResource() {
         org.apache.tomcat.util.descriptor.web.ContextResource resource = new org.apache.tomcat.util.descriptor.web.ContextResource();
         resource.setAuth("Container");
         resource.setName("jdbc/myDsName");
         resource.setType("javax.sql.DataSource");
         resource.setProperty("driverClassName", "nl.pinkroccade.jdbc.RollbackOnlyDriver");
         resource.setProperty("url", "...");
         resource.setProperty("username", "...");
         resource.setProperty("password", "...");
         return resource;
     }


Re: Tomcat embedded context: Unable to find [java:]

Posted by Tom Eugelink <tb...@tbee.org>.
Took a bit to find time again, but this indeed fixes the problem. Strange registering the ContextFactory didn't.

Thanks!



On 17-1-2017 20:56, Mark Thomas wrote:
> On 16/01/2017 09:13, Tom Eugelink wrote:
>> Trying to launch Tomcat 8.0.39 embedded with a datasource configured, I
>> get this error:
>>
>> /Failed to log into the database: Name [java:/comp/env/myDsName] is not
>> bound in this Context. Unable to find [java:]./
>>
>> I'm configuring the default Tomcat ContactFactory. This is the relevant
>> source:
>>
>>          System.setProperty("java.naming.factory.initial",
>> "org.apache.naming.java.javaURLContextFactory");
> Try replacing the above line with:
> tomcat.enableNaming();
>
> Mark
>
>
>>          StandardContext standardContext =
>> (StandardContext)tomcat.addWebapp("/mywebapp, "/path/to/web/resources");
>> standardContext.getNamingResources().addResource(createJdbcResource());
>>
>>          org.apache.catalina.webresources.StandardRoot standardRoot = new
>> org.apache.catalina.webresources.StandardRoot(standardContext);
>>          standardContext.setResources(standardRoot);
>>
>>      private static org.apache.tomcat.util.descriptor.web.ContextResource
>> createJdbcResource() {
>>          org.apache.tomcat.util.descriptor.web.ContextResource resource =
>> new org.apache.tomcat.util.descriptor.web.ContextResource();
>>          resource.setAuth("Container");
>>          resource.setName("jdbc/myDsName");
>>          resource.setType("javax.sql.DataSource");
>>          resource.setProperty("driverClassName",
>> "nl.pinkroccade.jdbc.RollbackOnlyDriver");
>>          resource.setProperty("url", "...");
>>          resource.setProperty("username", "...");
>>          resource.setProperty("password", "...");
>>          return resource;
>>      }
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat embedded context: Unable to find [java:]

Posted by Mark Thomas <ma...@apache.org>.
On 16/01/2017 09:13, Tom Eugelink wrote:
> Trying to launch Tomcat 8.0.39 embedded with a datasource configured, I
> get this error:
> 
> /Failed to log into the database: Name [java:/comp/env/myDsName] is not
> bound in this Context. Unable to find [java:]./
> 
> I'm configuring the default Tomcat ContactFactory. This is the relevant
> source:
> 
>         System.setProperty("java.naming.factory.initial",
> "org.apache.naming.java.javaURLContextFactory");

Try replacing the above line with:
tomcat.enableNaming();

Mark


> 
>         StandardContext standardContext =
> (StandardContext)tomcat.addWebapp("/mywebapp, "/path/to/web/resources");
> standardContext.getNamingResources().addResource(createJdbcResource());
> 
>         org.apache.catalina.webresources.StandardRoot standardRoot = new
> org.apache.catalina.webresources.StandardRoot(standardContext);
>         standardContext.setResources(standardRoot);
> 
>     private static org.apache.tomcat.util.descriptor.web.ContextResource
> createJdbcResource() {
>         org.apache.tomcat.util.descriptor.web.ContextResource resource =
> new org.apache.tomcat.util.descriptor.web.ContextResource();
>         resource.setAuth("Container");
>         resource.setName("jdbc/myDsName");
>         resource.setType("javax.sql.DataSource");
>         resource.setProperty("driverClassName",
> "nl.pinkroccade.jdbc.RollbackOnlyDriver");
>         resource.setProperty("url", "...");
>         resource.setProperty("username", "...");
>         resource.setProperty("password", "...");
>         return resource;
>     }
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org