1

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?

italiano40
  • 496
  • 9
  • 18
  • You might want to search for similar Tomcat issues, like this one: http://stackoverflow.com/questions/20854848/tomcat-error-warning-failed-to-retrieve-jndi-naming-context-for-container. It think the issue lies outside of HikariCP. – brettw Jan 21 '15 at 08:48
  • 1
    @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 '15 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 '15 at 02: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 '15 at 03:09
  • we have many users who use HikariCP with Tomcat. Maybe you can post a full stacktrace? – brettw Jan 22 '15 at 04:43
  • @brettw The javax.naming.NamingException is really a standard stack trace and it was always the line with factory attribute. I doubt that you have many users who use HikariCP since it was impossible to find a example context that worked for tomcat 7. – italiano40 Jan 22 '15 at 12:37
  • If you look at the bugs fixed here (https://github.com/brettwooldridge/HikariCP/issues?q=is%3Aissue+is%3Aclosed+tomcat) and look at the HikariCP Google group, you will find users who have and are using HikariCP with Tomcat 7 and 8. – brettw Jan 22 '15 at 15:22
  • @italiano40 ever find a solution to this? i am having this issue with 2.4.7 HikariCP, on Java 1.8 and tomcat7 – Jeryl Cook Oct 13 '16 at 14:26

1 Answers1

1

may be this could help you

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

adramazany
  • 625
  • 9
  • 15