Goal: Run a standalone Java & Database application in the cloud for performance, scalability and high availability
Application Details
- Spring Boot based Java application is git cloned in to a folder on the Google App Engine Standard Environment.
- Google Cloud SQL 2nd generation instance created
Note: The Cloud Shell is in the same Google Cloud project as the Cloud SQL
Google Cloud Shell
user@${PROJECT_ID}:~$ cd git
user@${PROJECT_ID}:~$ cd myapplication
Running application using Maven throws exception not being able to connect to the Cloud SQL database
user@${PROJECT_ID}:~$ mvn exec:java
Using different JDBC connection strings and JDBC drivers did not help.
application.properties
# Use MySQL database
#etl.datasource.url=jdbc:mysql://${IP:Instance_name}/${database}?autoReconnect=true&useSSL=false
#etl.datasource.url=jdbc:google:mysql://${INSTANCE_CONNECTION_NAME}/${database}
etl.datasource.url=jdbc:mysql://google/${database}?cloudSqlInstance=${INSTANCE_CONNECTION_NAME}&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false
#etl.datasource.driver-class-name=com.mysql.jdbc.Driver
etl.datasource.driver-class-name=com.mysql.jdbc.GoogleDriver
etl.datasource.username=${user}
etl.datasource.password=${password}
2017-08-03 10:40:59.477 ERROR 381 --- [MyApplication.main()] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool. com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
2017-08-03 12:16:23.525 ERROR 1048 --- [MyApplication.main()] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool. java.sql.SQLException: Unable to load class: com.mysql.jdbc.GoogleDriver from ClassLoader:java.net.URLClassLoader@13b428de;ClassLoader:java.net.URLClassLoader@13b428de
Even adding a src/webapp/WEB-INF/appengine-web.xml did not help.
appengine-web.xml
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<threadsafe>true</threadsafe>
<use-google-connector-j>true</use-google-connector-j>
</appengine-web-app>
Questions
- Is Google App Engine only for Web based applications?
- Is the Google App Engine Flexible environment suitable for non-web console based Java applications?
- Or should I be using the Google Compute Engine VM platform to run such non-web console applications and similar to running on my local computer?
- Is there a Maven dependency that can be added for com.mysql.jdbc.GoogleDriver?