Spring Boot web application with flyway.
So I switched from using H2 to MySQL and using Testcontainers to provide a DB for my backend tests when necessary.
Which means all my other integration tests (that don't require a database but require loading the spring application context) -- e.g. UI tests -- now fail because they don't have a DB to execute flyway migrations on.
[...]
[main] WARN com.zaxxer.hikari.util.DriverDataSource - Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
[main] ERROR com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.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 com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
[...]
at org.flywaydb.core.internal.database.DatabaseFactory.createDatabase(DatabaseFactory.java:72)
at org.flywaydb.core.Flyway.execute(Flyway.java:1670)
at org.flywaydb.core.Flyway.migrate(Flyway.java:1356)
[...]
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350
[...]
How can I suspend flyway migrations for these tests?
You should set spring.flyway.enabled=false. This can be done either using special profile in your tests or by using TestPropertySource annotation on your tests.
Related
I am using Hikari Connection Pool with Spring boot. I am using hikari connection pool and postgres with default configs.
I am seeing lot of warning like below
2023-01-31T06:07:54.4313140Z 2023-01-31 06:07:30.439 WARN [supplier,b516974ba1065b35,b516974ba1065b35] 12300 --- [ault-executor-1] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection#7d38668e (This connection has been closed.). Possibly consider using a shorter maxLifetime value.
2023-01-31T06:07:54.4313939Z 2023-01-31 06:07:30.440 WARN [supplier,b516974ba1065b35,b516974ba1065b35] 12300 --- [ault-executor-1] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Failed to validate connection org.postgresql.jdbc.PgConnection#7a88b46b (This connection has been closed.). Possibly consider using a shorter maxLifetime value.
I tried the below things as mentioned here. Both did not help
hikariConfig.addDataSourceProperty("socketTimeout", hikariConfig.getMaxLifetime() + TimeUnit.SECONDS.toMillis(1));
hikariConfig.addDataSourceProperty("idle_session_timeout", hikariConfig.getMaxLifetime() + TimeUnit.SECONDS.toMillis(1)); - With postgres 14.6
Version
HikariCP - 4.0.3
Spring Boot - 2.5.8
Postgres - 10.7
org.postgresql:postgresql - 42.5.1
I also tried upgrading postgres to the latest 14.6 and spring boot to 2.6.8. But still the same problem.
Can someone let me know what could be the problem & how to get around this warning?
I make a jar to connect to JMS provider, it's work fine in a server (a) but doesn't work on a server (b).
I verify that connection to the JMS provider from server (b) is OK via telnet as shown below:
-> telnet -d 10.127.161.247 4447
Trying 10.127.161.247...
Connected to 10.127.161.247.
The logs and exception that it's throw is below :
2018/08/01 11:19:47:921 - Processing command line arguments...
2018/08/01 11:19:47:927 - Preparing the output... Writing to file = true
2018/08/01 11:19:50:315 - Trying to establish connection, attempt: 0
2018/08/01 11:19:52:132 - Connecting to provider: remote://10.127.161.247:4447 using user: oad_user
2018/08/01 11:19:52:132 - Creating a regular (non-secure) connection factory...
2018/08/01 11:19:53:073 - Opening a connection to the JMS provider...
2018/08/01 11:20:24:192 - Attempt failed: Failed to create session factory
javax.jms.JMSException: Failed to create session factory
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:675)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createTopicConnection(ActiveMQConnectionFactory.java:267)
at com.alcatel.ossgw.client.jms.JmsSubscriberClient.prepareConnection(JmsSubscriberClient.java:334)
at com.alcatel.ossgw.client.jms.JmsSubscriberClient.connect(JmsSubscriberClient.java:274)
at com.alcatel.ossgw.client.jms.JmsSubscriberClient.listen(JmsSubscriberClient.java:97)
at com.alcatel.ossgw.client.jms.JmsSubscriberClient.main(JmsSubscriberClient.java:536)
Caused by: ActiveMQNotConnectedException[errorType=NOT_CONNECTED message=AMQ119007: Cannot connect to server(s). Tried with all available servers.]
at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:818)
at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:67
I don't how to debug such a problem knowing i'm new in JMS, i'll be grateful for any remarks and ideas..
Many thanks
Did you ever find out why this was happening?
I have a related issue where an active JMS connection suddenly disconnects and the system starts throwing this exception until a system restart is done and then it connects again without fail.
While connecting to an AWS rds mysql instance I am getting the below error.
This happens only when I deploy 2 different wars on the same tomcat instance. Both apps connect to their corresponding DB instance (Separate DBs).
If I deploy them separately I don't have an issue.
Here is the error:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
27-Jul-2018 18:31:06.214 SEVERE [pool-27-thread-3] org.apache.tomcat.jdbc.pool.ConnectionPool.init Unable to create initial connections of pool.
com.mysql.cj.jdbc.exceptions.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 com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:741)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:57)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1663)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:662)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:221)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:307)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:200)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:728)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:662)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:480)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:115)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:102)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:126)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139)
please help me with starting WAR Spring MVC Web app on AWS (Amazon Web service)
it fails with connection timeout to database ( to RDS - also Amazon).
I works localy absolutely fine. via tomcat it connects to my RDS and works,
but when I deploy this war on AWS - timeout.
I tried to add configs to increase timeout, but seems it is ignored by AWS.
Could you please help ??
structure of WAR file:
-META-INF
-WEB-INF
|- classes
|- lib
|- view (*.jsp here)
-.ebextensions
|- timeout.config
timeout.config content:
option_settings:
- namespace: aws:elasticbeanstalk:command
option_name: Timeout
value: 1800
Logs :
Where com.books.dao.impl.GenreDAOImpl.findAll(GenreDAOImpl.java:49) my first request to DB.
16-Jun-2018 20:24:46.050 SEVERE [http-nio-8080-exec-8] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcher] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection] with root cause
java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:161)
at oracle.net.nt.ConnOption.connect(ConnOption.java:159)
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:428)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:506)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:595)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:230)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1452)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:496)
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:196)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:159)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:394)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:474)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:484)
at com.books.dao.impl.GenreDAOImpl.findAll(GenreDAOImpl.java:49)
Security for elasticbeanstalk
Security Group for elastic bean
Security for ec2
Security Group for EC2 instance where public access failed
Actually, it's not an issue of config file not working, its due to security group is blocking for port or not allowing your application to get connected with your Database.
So if you are using RDS Instance then check the Security Group of your RDS, and also in which VPC it is. Best is just try to ping your RDS Instance and see whether you are getting the reply from it or not.
If you are using Mysql, Running inside your Instance, then just Allow the port (3306 for MySQL) in your EC2 Security Group. As your Port is not open, so AWS won't able to make the connection
In this case, you have to Install Mysql in your Instance if not installed before the deployment.
What happens it when you try with your Local development (Tomcat), So what happens is, in our code, we have mention localhost:3306 as the connection URL and being on the same machine (your development and MySQL) it works fine.
I am trying to deploy my springboot application on an AWS linux instance however i keep getting the following error :
2018-04-24 18:15:27.777 INFO 24020 --- [ost-startStop-1]
o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-04-24 18:15:28.771 ERROR 24020 --- [main] 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) ~[na:1.8.0_161]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_161]
...
2018-04-24 16:58:57.522 WARN 23780 --- [main] o.s.b.a.orm.jpa.DatabaseLookup : Unable to determine jdbc url from datasource
org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException:
Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
This is how i created my applications.properties file :
#database config
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://****-west-1.rds.amazonaws.com:3306/DevManagementDB
spring.datasource.username=root
spring.datasource.password=mypassword
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
The strange part is that i can connect to my RDS database from this springboot application when i am running the application on my local machine. As soon as i try to deploy the application to the linux instance on AWS it fails and i get the above errors.
If your DB is an RDS instance, make sure the public IP address of the device accessing the DB is included in the RDS instance's Security Group. Also make sure the public IP address is included in Inbound channel of the appropriate VPC security group.
I have also faced similar problem.
I have to update my mysql extra parameters from /etc/mysql/mysql.conf.d/mysqld.cnf
Stop mysql server sudo systemctl stop mysql.service
Need to update
bind-address = 0.0.0.0 // replace 0.0.0.0 with required ip, 0.0.0.0 allows all ip
Start mysql server sudo systemctl start mysql.service
also need to create a user who has access with that ip, add permission in mysql
mysql > CREATE USER 'user_name'#'%' IDENTIFIED BY 'PASSWORD'; // replace % with appropriate IP
mysql > CREATE USER 'user_name'#'%' IDENTIFIED BY 'PASSWORD'; // replace % with appropriate IP
mysql > GRANT ALL PRIVILEGES ON *.* TO 'user_name'#'%' WITH GRANT OPTION; // replace % with appropriate IP
mysql > FLUSH PRIVILEGES;
Hope this will help someone