I'm able to upload the mysql connector as a jdbc driver, and I can create a datasource manually based on it. Unfortunately, when I try to deploy a datasource, it does not work failing with a message about the driver not found.
It looks like MySQL has two different drivers; com.mysql.jdbc.Driver and com.mysql.fabric.jdbc.FabricMySQLDriver. You'll see in the following CLI command you'll see the installed driver name doesn't match.
Thanks for entering the discussion. I've read before that you should deploy mysql as a module, but I couldn't find out how to do that from maven. There was a discussion on stackoverflow more than a year ago now (How to deploy mysql datasource using jboss-as-maven-plugin - Stack Overflow), of someone saying they wrote their own plugin to do that, but I couldn't find what the name of this plugin is and if it's available.
The approach of James does work (therefore I selected it as the answer) but it's not ideal, i.e. you'd have to find out the correct name of the driver from inside the artifact, maybe the naming convention will change in the future again. Therefore I'd prefer the module way...
I am trying to deploy a java application (Spring boot maven) using cloud run. This application needs a connect to MySQL database which is created in google cloud SQL. I have a created a IAM and Admin service account and provides roles like Cloud SQL Admin, Cloud SQL Client, Cloud SQL Editor, Cloud SQL Instance User, Storage Object Creator. After creating the service account I have generated the key file as json and using it in my java application . I am able to connect to the MySQL instance when running from my local machine. But when I try to deploy it through cloud run I am facing errors when building google image from the application. I tried below command.
The error message you're encountering indicates a permissions issue related to accessing your Cloud SQL instance. The key message here is "Not authorized to access resource. Possibly missing permission cloudsql.instances.get on resource instances/testdb." This suggests that the service account used during the build process in Google Cloud Build does not have sufficient permissions to access the Cloud SQL instance.
could be due to several reasons, including incorrect credentials, the way the credentials are being used, or the configuration of your Spring Boot application. Let's go through some steps to troubleshoot and resolve this issue:
Correct Credentials: Ensure that the credentials provided in the credentials.json file are correct. This file should contain the service account key for the IAM Admin service account you created.
Service Account Permissions: Double-check that the IAM Admin service account has the necessary roles (Cloud SQL Admin, Cloud SQL Client, Cloud SQL Editor, Cloud SQL Instance User, Storage Object Creator) and that these roles are properly assigned.
Database User Authentication: The error mentions the user 'root'. Ensure that this user exists in your MySQL database and has the correct permissions. Also, verify that you are using the correct username and password in your application properties. If you're using Cloud SQL's IAM database authentication, ensure that it's configured correctly.
Use of credentials.json: Storing credentials.json in src/main/resources is generally not recommended for security reasons, especially when deploying to production. Instead, consider using environment variables or secret management services to handle credentials. For local testing, ensure that the path to credentials.json is correctly specified in spring.cloud.gcp.credentials.location.
Database Connection Properties: Verify that the database connection properties in application.properties are correct. The instance-connection-name should be in the format ::. Ensure that there are no typos or incorrect values.
Cloud SQL Proxy: If you are using the Cloud SQL Proxy for local testing, ensure that it is running and configured correctly. The proxy provides a secure connection to your Cloud SQL instance for testing on your local machine.
Testing in a Different Environment: If possible, test the connection to the Cloud SQL instance from a different environment (e.g., another machine or a CI/CD pipeline) to rule out local environment issues.
The error "java.net.UnknownHostException: google" typically arises when your application is unable to resolve the hostname google during database connection establishment. This suggests that the SocketFactory responsible for creating the connection to Cloud SQL is not being properly initialized or recognized. Here are steps to debug and resolve the connections issues:
Correct JDBC URL Format: It's important to use the correct JDBC URL format for Cloud SQL connections. The format provided as jdbc:mysql://google/... can cause issues because "google" is not a valid hostname. Instead, use a URL formatted as follows, ensuring it explicitly specifies the cloud SQL instance and uses the correct socket factory if required by your setup:
Dependency Check: If the Spring Cloud GCP 5.x documentation confirms that the socket factory configuration is automatically managed, you do not need to include the mysql-socket-factory-connector-j-8 dependency. However, if auto-configuration is not mentioned, or if you encounter issues, including this dependency may still be necessary.
Verify Version Compatibility: Ensure that the spring-cloud-gcp-starter version you use is compatible with the Spring Cloud and Spring Boot versions in your project to avoid any conflicts.
IAM Roles: Make sure the IAM service account associated with your application has the necessary roles, such as Cloud SQL Client and Cloud SQL Editor if database management is required.
However, for migrating the library it must first pass IP review. This page features a first analysis of the OT/JPA dependencies in order to assess necessary changes before migrating to the eclipse repositories.
Not okay. Plexus code was rejected in the past (f.e. CQ 3161).
Suggested solution: Rewrite the compiler plugin for maven and drop support for maven 2. Maven 3 uses google guice as a container, which will pass the eclipse IP review.