I wanted to know how easy it would be to get Spring-Boot auto-reconfiguration to work in OpenShift. It did not really work for me in Cloud Foundry without some massaging ( auto re-config blog ).

The proper way would be to extend https://github.com/spring-projects/spring-cloud/tree/master/spring-cloud-core for OpenShift Which is probably dead simple, too, but I wanted to do a quick 30 minute hack which become about a 90 minutes dirty hack.

In simple terms, the cartridge always sets -Dspring.profiles.active=cloud (unless this is overwritten by the app developer). And when it finds a ‘OPENSHIFT_MYSQL_DB_URL’ environment variable (which means the user added that service (cartridge) to the application, then the cartridge will add a the MariaDB (MySQL) information to ‘VCAP_SERVICES’ In addition I als set ‘VCAP_APPLICATION’ to some partially correct values, as well as VCAP_APP_HOST and VCAP_APP_PORT.

Then I deployed the jar generated from the unfamous-quotes cloud-foundry-autoreconfig-tests branch and it correctly picked up the MySQL DB and SUCCESS.

It was ridiculously easy to get that working in OpenShift. If I hadn’t put in a typo in one of my first attempts it would have been even easier.

What I did not mentioned in the last blog was that the version of the “unfamous quotes” code only works on Cloud Foundry if there is a data source supplied by Cloud Foundry. Otherwise you get:

org.springframework.cloud.CloudException: No unique service matching interface javax.sql.DataSource found. Expected 1, found 0

This happens due to the this code in DataSourceConfiguration:

return connectionFactory().dataSource();    

With the current version of the spring runner cartridge the same happens: You have to add a MariaDB or it wont work.

Since this was just a quick and dirty test, I did not add any other DB services. But I also would rather check out the spring-core-cloud and create an OpenShift Cloud Connector.


Started by making sure that the latest version still works.

I already confirmed with Active State that you cannot upload a JAR directly, but have to unpack it so:

from the working dir (same level as pom.xml)
cd ./unpacked/; unzip ../target/unfamous-quotes-0.0.1-SNAPSHOT.jar; ls -al; cd ..
stackato push –path ./unpacked/

But the application starts up on port 8080 which is not the port stackato wants it to run at and then it is killed and restarted and ..
application.properties still has an entry about the server.port which I commented out and retried. But the server still started on
port 8080. So I made sure that the application.properties file was really updated which it was.

In between tries I always removed application including the route with

stackato delete unfamous-quotes

No luck. nothing helped.
I don’t understand though since I have an example that works and this app worked fine before I did some static file changes.

No matter what I check or do stackato is not able to assign the right port and the server runs on 8080 until it is killed of.
Of course I could set the port like for my simple server test but that defeats the purpose.

Besides, the exact same JAR works on Pivotal’s Cloud Foundation free tier run.pivotal.io with a simple push.

cf push unfamous-quotes -p ./target/unfamous-quotes-0.0.1-SNAPSHOT.jar

Next I tried another trick that I already learned in my experiments. I upload the jar with Eclipse (STS)
Or you can also push with CF, but then I would have to log out of run.pivotal.io – which I am using in parallel –
and into stackato, which also works. But unlike the stackato CLI the cf CLI does not allow multiple targets
and swithcing between them. So Eclispe it is.
The push with Eclipse (or cf) will fail, too, but all it requires is a start of the app and the same jar works in stackato.

Except that this does not resolve anything, the server still tstats on

Setting the JAVA_OPTS environment variable has the same escaping problems as before, too.

At this stage I am ready for one of my once in a month stress-release cigarettes.
The stackato web UI does not do anything to calm me down, either. e.g. the page refresh is annoying.

Even cf set-env did not work I assume there is an incompatibility with the build back

since the logs show this, which neither seems to work nor does it contain any of my environment variables:

stackato[dea_ng.0]: Launching web process: $PWD/.java-buildpack/open_jdk/bin/java -cp $PWD/.:$PWD/.java-buildpack/spring_auto_reconfiguration/spring_auto_reconfiguration-0.8.9.jar -Djava.io.tmpdir=$TMPDIR -XX:MaxPermSize=64M -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk/bin/killjava.sh -XX:PermSize=64M -Xms382293K -Xmx382293K -Xss995K org.springframework.boot.loader.JarLauncher --server.port=$PORT

And I give up for now.