Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Trying to install HikariCP on tomcat 7 and getting javax.naming.NamingException on startup

Ask Question

I am trying to configure HikariCP as my datasource connection pool on tomcat 7 with mysql. Here is my context file...

    <?xml version="1.0" encoding="UTF-8"?>
    <Context allowCasualMultipartParsing="true">
   <Resource name="jdbc/application" auth="Container"
      factory="com.zaxxer.hikari.HikariJNDIFactory"
      type="javax.sql.DataSource"
      minimumIdle="5" 
      maximumPoolSize="10"
      connectionTimeout="300000"
      dataSource.implicitCachingEnabled="true" 
      dataSource.user="root"
      dataSource.password="pass"
      dataSource.url="jdbc:mysql://localhost:3306/Database"/>
    </Context>

But on startup I get this error...

WARNING: Failed to retrieve JNDI naming context for container

javax.naming.NamingException: No naming context bound to this class loader

How can I configure HikariCP-2.3.0 on tomcat?

You might want to search for similar Tomcat issues, like this one: stackoverflow.com/questions/20854848/…. It think the issue lies outside of HikariCP. – brettw Jan 21, 2015 at 8:48 @brettw I think it is connected to hikariCP cause when I use just a jdbc mysql driver it works, as soon as I add the factory attribute to the resource it throws that error. – italiano40 Jan 21, 2015 at 16:57 But using just the JDBC driver does not involve JNDI, the issue is that there is no JNDI InitialContext available, so the HikariJNDIFactory cannot possibly work. You need to figure out why a JNDI naming context is not available in the container. Again, I suggest googling for "Failed to retrieve JNDI naming context for container" to find how users resolved this same issue. – brettw Jan 22, 2015 at 2:48 @brettw It is obviously a problem with the HikariCP library and it was not never meant to work with tomcat, I have since switched to C3P0 worked the first time. Which is a similar context file as to HikariCP. – italiano40 Jan 22, 2015 at 3:09

Configuring the Tomcat Definitions

Location of your JNDI datasource definitions depends upon the scope for the connections. You can define them globally by specifying them in Tomcat's conf/server.xml and conf/context.xml, or you can scope them to individual applications by defining them in conf/Catalina/localhost/WebAppContext.xml (where WebAppContext is the web application context for the app, basically the directory name from Tomcat's webapps directory).

<Resource name="jdbc/LiferayPool" auth="Container"
  factory="com.zaxxer.hikari.HikariJNDIFactory"
  type="javax.sql.DataSource"
  minimumIdle="5" 
  maximumPoolSize="10"
  connectionTimeout="300000"
  dataSourceClassName="org.postgresql.ds.PGSimpleDataSource"
  dataSource.url="jdbc:postgresql://localhost:5432/lportal"
  dataSource.implicitCachingEnabled="true" 
  dataSource.user="user"
  dataSource.password="pwd" />

https://community.liferay.com/blogs/-/blogs/tomcat-hikaricp

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.