Usage of spring application index

CleverDev :

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: 
Nikolas :

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:

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());
    }
    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=68025&siteId=1