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;
    }

Reply via email to