How to override applicationContext.getId() with spring boot 2.0?

Viewed 1074

We have recently upgraded to spring boot 2.0 and noticed that the application context IDs aren't unique any more. Previously, if we set spring.application.index, ContextIdApplicationContextInitializer would use that to construct the application context id. I now see that in spring 2.0, the implementation was significantly changed. How best should id be set? The goal is to include the hostname as part of the id to keep systems distinct. The spring cloud docs still refer to the old way: Service ID Must Be Unique.

UPDATE What used to happen is that spring.application.name was set in the source code of the project (ie my-app) and spring.application.index would be set in the runtime (ie, 1e4f630be), then applicationContext.id would have the value of my-app-1e4f630be. Now, it always has the value of my-app-1. The implemenation of ContextIdApplicationContextInitializer no longer references spring.application.index. This is a significant change between versions and I haven't found examples or documentation on how to customize the id properly with spring boot 2.0

0 Answers
Related