springboot启动,报jdbc连接池的错误

2017-03-07 11:40:16.127 ERROR 31460 --- [pool-1-thread-1] o.a.tomcat.jdbc.pool.ConnectionPool      : Unable to create initial connections of pool.


com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure


The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)


2017-03-07 11:40:16.129 ERROR 31460 --- [pool-1-thread-1] o.s.s.s.TaskUtils$LoggingErrorHandler    : Unexpected error occurred in scheduled task.


org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure


The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:252)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:447)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:277)


        报错的时候一直觉得是数据库连接池的问题,各种核对数据库配置的问题。网上说的是要修改mysql的配置文件,但是觉得不太靠谱,然后又在jdbc的url上添加amp,依然不奏效。然后发现我们的项目是springboot发布启动的,application.yml配置的是,我们的打包命令是

package -P test -D maven.test.skip=true

,打包后的配置文件中的

spring:
          profiles:
            active: test 

是正确的,我们的安装springboot命令为:nohub java -jar xxx.jar。应该是没问题的,但是发现项目启动时打的包并不是active:test下的包。

换了启动命令  java -jar -Dspring.profiles.active=test  xxx.jar ,启动才正确没报错,问题解决。

总结原因:应该是spring.profiles的配置未生效导致的。

你可能感兴趣的:(java错误,jar,连接池错误)