Can someone please clarify what is the usage of spring.application.index
property and why do we need it?
Application.yml:
spring:
application:
name: ServiceName
index:
As far as I see, the spring.application.index
has been considered deprecated since the version 2.0.0.RC1
. I judge from comparing the following these appendices:
- Spring Boot
2.0.0.M7
: Common application properties where thespring.application.index
is mentioned. - Spring Boot
2.0.0.RC1
: Common application properties where thespring.application.index
is not mentioned.
The previous statement is proved by inspecting the source codes of the ContextIdApplicationContextInitializer
across these versions:
Version
2.0.0.M7
ContextIdApplicationContextInitializer. These versions provide more variability in customization the application index used for ApplicationContextID creation./** * Placeholder pattern to resolve for application index. The following order is used * to find the name: * <ul> * <li>{@code vcap.application.instance_index}</li> * <li>{@code spring.application.index}</li> * <li>{@code server.port}</li> * <li>{@code PORT}</li> * </ul> * This order favors a platform defined index over any user defined value. */`"${vcap.application.instance_index:${spring.application.index:${server.port:${PORT:null}}}}"`
Version
2.0.0.RC1
ContextIdApplicationContextInitializer. There could be find the index is incremented using automatically usingAtomicLong
, which also assures its uniqueness. See the innerContextIdApplicationContextInitializer$ContextId
class for more detail in the source. The key method is its constructor:ContextId createChildId() { return new ContextId(this.id + "-" + this.children.incrementAndGet()); }