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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



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

Reply via email to