Have you ever found yourself in a situation during development where you know the problem is some small detail that you’re overlooking but you can’t for the life of you figure it out? Pro tip, walk away and come back later.
Recently I was working on some older code. It was a Spring Boot app that at the time I originally wrote it, was not registering with a Eureka server. Everything was working just fine, until I decided to centralize the application’s config in my config server. So I copied the contents of my
application.yml file and added them to the config server before removing the
application.yml file locally. Next I proceeded to tell my application how to connect to Eureka. I simply added a program argument to the run configuration in my IDE since that’s what I always do in development.
Lo and behold, connection refused. My app would not start because it relied on the configuration which was now on my config server, but my app could not connect to Eureka in order to resolve the configuration server connection. What was the problem? 🤔
I literally wasted a good couple hours trying to figure this out. What confused me more is that another application I had written worked just fine in development and connected to the same Eureka server without any issue. This is the point where I just walked away and decided to come back later. So later that evening while cleaning up from dinner with the family, I had a flash… 😲
Have a look at my
main method and see if you can spot the error.
If you haven’t spotted it yet, have a look at this
main method and you should see the difference instantly.
You see, the
SpringApplication.run method does not oblige you to pass in program arguments. In my case, this being an older app that did not previously connect to Eureka, it never occurred to me that I wasn’t passing the program arguments. After passing the program arguments to the
SpringApplication.run method, I was off to the races.
Sometimes it really is the small details you’ve overlooked that make all the difference.