{"action":"created","issue":{"url":"https://api.github.com/repos/brettwooldridge/HikariCP/issues/474","labels_url":"https://api.github.com/repos/brettwooldridge/HikariCP/issues/474/labels{/name}","comments_url":"https://api.github.com/repos/brettwooldridge/HikariCP/issues/474/comments","events_url":"https://api.github.com/repos/brettwooldridge/HikariCP/issues/474/events","html_url":"https://github.com/brettwooldridge/HikariCP/issues/474","id":113759192,"number":474,"title":"com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization: Communications link failure","user":{"login":"dolphineor","id":9883493,"avatar_url":"https://avatars.githubusercontent.com/u/9883493?v=3","gravatar_id":"","url":"https://api.github.com/users/dolphineor","html_url":"https://github.com/dolphineor","followers_url":"https://api.github.com/users/dolphineor/followers","following_url":"https://api.github.com/users/dolphineor/following{/other_user}","gists_url":"https://api.github.com/users/dolphineor/gists{/gist_id}","starred_url":"https://api.github.com/users/dolphineor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dolphineor/subscriptions","organizations_url":"https://api.github.com/users/dolphineor/orgs","repos_url":"https://api.github.com/users/dolphineor/repos","events_url":"https://api.github.com/users/dolphineor/events{/privacy}","received_events_url":"https://api.github.com/users/dolphineor/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-28T07:25:12Z","updated_at":"2015-10-28T07:37:22Z","closed_at":"2015-10-28T07:37:22Z","body":"Hi brettwooldridge, I'm using HikariCP as MySQL'dataSource with Spring Boot recently, but found some problems.\r\nThis is my hikari config in application.yml:\r\n\r\n```\r\nhikari:\r\n    poolName: HikariCP\r\n    minimumIdle: 5\r\n    maximumPoolSize: 25\r\n    connectionTimeout: 30000\r\n    idleTimeout: 30000\r\n    connectionTestQuery: SELECT 1\r\n    dataSourceClassName: com.mysql.jdbc.jdbc2.optional.MysqlDataSource\r\n    dataSourceProperties:\r\n        url: jdbc:mysql://127.0.0.1:13206/reactive?characterEncoding=UTF-8\r\n        user: test\r\n        password: test1234\r\n        ## Only for mysql\r\n        cachePrepStmts: true\r\n        prepStmtCacheSize: 300\r\n        prepStmtCacheSqlLimit: 2048\r\n```\r\nAnd the corresponding Java Bean is:\r\n```\r\n/**\r\n * provide url, user, password by calling addDataSourceProperty method\r\n */\r\n@Bean\r\n    public DataSource dataSource() {\r\n        HikariConfig configuration = new HikariConfig();\r\n        configuration.setPoolName(poolName);\r\n        configuration.setMinimumIdle(minimumIdle);\r\n        configuration.setMaximumPoolSize(maximumPoolSize);\r\n        configuration.setConnectionTimeout(connectionTimeout);\r\n        configuration.setIdleTimeout(idleTimeout);\r\n        configuration.setConnectionTestQuery(connectionTestQuery);\r\n        configuration.setDataSourceClassName(dataSourceClassName);\r\n\r\n        configuration.addDataSourceProperty(\"url\", url);\r\n        configuration.addDataSourceProperty(\"user\", user);\r\n        configuration.addDataSourceProperty(\"password\", password);\r\n        configuration.addDataSourceProperty(\"cachePrepStmts\", cachePrepStmts);\r\n        configuration.addDataSourceProperty(\"prepStmtCacheSize\", prepStmtCacheSize);\r\n        configuration.addDataSourceProperty(\"prepStmtCacheSqlLimit\", prepStmtCacheSqlLimit);\r\n\r\n        return new HikariDataSource(configuration);\r\n    }\r\n```\r\nIn this case, the connection pool works fine. When I use other configuration, exception occurred, as following:\r\n```\r\nhikari:\r\n    poolName: HikariCP\r\n    jdbcUrl: jdbc:mysql://127.0.0.1:13206/reactive?characterEncoding=UTF-8\r\n    username: test\r\n    password: test1234\r\n    minimumIdle: 5\r\n    maximumPoolSize: 25\r\n    connectionTimeout: 30000\r\n    idleTimeout: 30000\r\n    connectionTestQuery: SELECT 1\r\n    dataSourceClassName: com.mysql.jdbc.jdbc2.optional.MysqlDataSource\r\n    dataSourceProperties:\r\n        ## Only for mysql\r\n        cachePrepStmts: true\r\n        prepStmtCacheSize: 300\r\n        prepStmtCacheSqlLimit: 2048\r\n\r\n/**\r\n * provide jdbcUrl, username, password instead of calling addDataSourceProperty method\r\n */\r\n@Bean\r\n    public DataSource dataSource() {\r\n        HikariConfig configuration = new HikariConfig();\r\n        configuration.setPoolName(poolName);\r\n        configuration.setJdbcUrl(jdbcUrl);\r\n        configuration.setUsername(username);\r\n        configuration.setPassword(password);\r\n        configuration.setMinimumIdle(minimumIdle);\r\n        configuration.setMaximumPoolSize(maximumPoolSize);\r\n        configuration.setConnectionTimeout(connectionTimeout);\r\n        configuration.setIdleTimeout(idleTimeout);\r\n        configuration.setConnectionTestQuery(connectionTestQuery);\r\n        configuration.setDataSourceClassName(dataSourceClassName);\r\n\r\n        configuration.addDataSourceProperty(\"cachePrepStmts\", cachePrepStmts);\r\n        configuration.addDataSourceProperty(\"prepStmtCacheSize\", prepStmtCacheSize);\r\n        configuration.addDataSourceProperty(\"prepStmtCacheSqlLimit\", prepStmtCacheSqlLimit);\r\n\r\n        return new HikariDataSource(configuration);\r\n    }\r\n```\r\nThe **exception** information is:\r\n```\r\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.\r\n\tat org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:571)\r\n\tat org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)\r\n\tat org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)\r\n\t... 30 more\r\nCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [com/github/dolphineor/springboot/configure/JpaConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization: Communications link failure\r\n\r\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.\r\n\tat org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)\r\n\tat org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)\r\n\tat org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:543)\r\n\t... 32 more\r\nCaused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization: Communications link failure\r\n\r\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.\r\n\tat org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)\r\n\tat org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)\r\n\t... 44 more\r\nCaused by: com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization: Communications link failure\r\n\r\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.\r\n\tat com.zaxxer.hikari.pool.HikariPool.initializeConnections(HikariPool.java:581)\r\n\tat com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:152)\r\n\tat com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:73)\r\n\tat com.github.dolphineor.springboot.configure.JpaConfig.dataSource(JpaConfig.java:80)\r\n\tat com.github.dolphineor.springboot.configure.JpaConfig$$EnhancerBySpringCGLIB$$20918aa0.CGLIB$dataSource$1(<generated>)\r\n\tat com.github.dolphineor.springboot.configure.JpaConfig$$EnhancerBySpringCGLIB$$20918aa0$$FastClassBySpringCGLIB$$cf46bcfb.invoke(<generated>)\r\n\tat org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)\r\n\tat org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:318)\r\n\tat com.github.dolphineor.springboot.configure.JpaConfig$$EnhancerBySpringCGLIB$$20918aa0.dataSource(<generated>)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:497)\r\n\tat org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)\r\n\t... 45 more\r\nCaused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure\r\n\r\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.\r\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\r\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)\r\n\tat java.lang.reflect.Constructor.newInstance(Constructor.java:422)\r\n\tat com.mysql.jdbc.Util.handleNewInstance(Util.java:404)\r\n\tat com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:983)\r\n\tat com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:339)\r\n\tat com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2252)\r\n\tat com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2285)\r\n\tat com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2084)\r\n\tat com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)\r\n\tat com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)\r\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\r\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)\r\n\tat java.lang.reflect.Constructor.newInstance(Constructor.java:422)\r\n\tat com.mysql.jdbc.Util.handleNewInstance(Util.java:404)\r\n\tat com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)\r\n\tat com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)\r\n\tat com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:422)\r\n\tat com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:134)\r\n\tat com.zaxxer.hikari.pool.HikariPool.addConnection(HikariPool.java:496)\r\n\tat com.zaxxer.hikari.pool.HikariPool.initializeConnections(HikariPool.java:565)\r\n\t... 58 more\r\nCaused by: java.net.ConnectException: connection refused\r\n\tat java.net.PlainSocketImpl.socketConnect(Native Method)\r\n\tat java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)\r\n\tat java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)\r\n\tat java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)\r\n\tat java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)\r\n\tat java.net.Socket.connect(Socket.java:589)\r\n\tat com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:214)\r\n\tat com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:298)\r\n\t... 74 more\r\n```\r\n\r\nThe network's solution is setting MySQL's wait_timeout and interactive_timeout, but it doesn't work.\r\n\r\ndolphineor.\r\n"},"comment":{"url":"https://api.github.com/repos/brettwooldridge/HikariCP/issues/comments/151752989","html_url":"https://github.com/brettwooldridge/HikariCP/issues/474#issuecomment-151752989","issue_url":"https://api.github.com/repos/brettwooldridge/HikariCP/issues/474","id":151752989,"user":{"login":"dolphineor","id":9883493,"avatar_url":"https://avatars.githubusercontent.com/u/9883493?v=3","gravatar_id":"","url":"https://api.github.com/users/dolphineor","html_url":"https://github.com/dolphineor","followers_url":"https://api.github.com/users/dolphineor/followers","following_url":"https://api.github.com/users/dolphineor/following{/other_user}","gists_url":"https://api.github.com/users/dolphineor/gists{/gist_id}","starred_url":"https://api.github.com/users/dolphineor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dolphineor/subscriptions","organizations_url":"https://api.github.com/users/dolphineor/orgs","repos_url":"https://api.github.com/users/dolphineor/repos","events_url":"https://api.github.com/users/dolphineor/events{/privacy}","received_events_url":"https://api.github.com/users/dolphineor/received_events","type":"User","site_admin":false},"created_at":"2015-10-28T07:37:22Z","updated_at":"2015-10-28T07:37:22Z","body":"^_^Thanks a lot, it works."}}