0
votes

I am not able to get my SpringBoot application linked with a mySQL POD in Openshift v3.

What I did so far:

  • Got a basic spring boot application up and running in openshift v3.
  • Added a mysql application. The pod is up and running without errors.
  • Added the datasource configuration in application.properties of my spring boot app:

    spring.datasource.url=jdbc:mysql://mysql:3306/${MYSQL_DATABASE}\ spring.datasource.username=${MYSQL_USER} spring.datasource.password=${MYSQL_PASSWORD}

  • linked spring boot app with mysql db by executing the command:

oc env dc shoppinglist -e MYSQL_USER=dbuser -e MYSQL_PASSWORD=dbpassword -e MYSQL_DATABASE=shoppingdb

deploymentconfig "shoppinglist" updated

However, the spring boot pod is crashing because it cannot access the mysql db with the given user:

 2017-12-29 13:35:00.806 ERROR 1 --- [           main]
 o.a.tomcat.jdbc.pool.ConnectionPool      : Unable to create initial
 connections of pool. java.sql.SQLException: **Access denied for user
 ''@'172.17.0.7'** (using password: YES)

Somehow, the username is lost. I guess something with my oc env settings is weard? I have no glue...

I do not know what is wrong so far and appreciate any help. Thanks!

1
After adding the env variables, do you redeploy the pod? Because the env variables aren't immediately set, only after a fresh deployment does it pick up a new configuration.Will Gordon
Setting environment variables on a deployment config would in the normal case trigger an automatic restart. The issue is whether environment variable references in application.properties are expanded. Anyway, run oc debug dc shoppinglist and at the shell prompt run env to verify that the environment variables are passed into the container as first step.Graham Dumpleton
I redeployed but it does not change the result.Tom
@Graham Dumpleton: I also tried oc debug dc shoppinglist. Response is: Error from server (NotFound): pods "dc" not found I am wondering why this does not work, because when I execute oc get all, it returns besides others dc/shoppinglist So syntax is correct, isn't it ?Tom
Try oc debug dc/shoppinglist. Usually commands will accept single combined argument, or as split values. Maybe that command doesn't for some reason.Graham Dumpleton

1 Answers

0
votes

Happy new year! And Thanks to everybody supporting me in finding the solution to my issue. I learned a lot but at the end it was just a typo in my application.properties:

spring.datasource.url=jdbc:mysql://mysql:3306/${MYSQL_DATABASE}\ 

It was propably a copy and paste issue (embarissing..) I have overseen the backslash after {MYSQL_DATABASE}all the time.

Thanks again for any help!