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:
2.0.0.M7
: Common application properties where the spring.application.index
is mentioned.2.0.0.RC1
: Common application properties where the spring.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 using AtomicLong
, which also assures its uniqueness. See the inner ContextIdApplicationContextInitializer$ContextId
class for more detail in the source. The key method is its constructor:
ContextId createChildId() {
return new ContextId(this.id + "-" + this.children.incrementAndGet());
}
You can find this property in Spring sources:
private static final String INDEX_PATTERN =
"${vcap.application.instance_index:${spring.application.index:${server.port:${PORT:null}}}}";
As the Javadoc of this class says, it is used to create ApplicationContextID which is a unique id of an application context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With