protected WebEnvironment determineWebEnvironment(ServletContext servletContext) {

        Class<? extends WebEnvironment> webEnvironmentClass = webEnvironmentClassFromServletContext(servletContext);
        WebEnvironment webEnvironment = null;

        // try service loader next
        if (webEnvironmentClass == null) {
            webEnvironment = webEnvironmentFromServiceLoader();
        }

        // if webEnvironment is not set, and ENVIRONMENT_CLASS_PARAM prop was not set, use the default
        if (webEnvironmentClass == null && webEnvironment == null) {
            webEnvironmentClass = getDefaultWebEnvironmentClass(servletContext);
        }

        // at this point, we anything is set for the webEnvironmentClass, load it.
        if (webEnvironmentClass != null) {
            webEnvironment = (WebEnvironment) ClassUtils.newInstance(webEnvironmentClass);
        }

        return webEnvironment;
    }
Return the WebEnvironment implementation class to use, based on the order of:
<ul>
    <li>A custom WebEnvironment class
             - specified in the {@code servletContext} {@link #ENVIRONMENT_ATTRIBUTE_KEY} property</li>
    <li>{@code ServiceLoader.load(WebEnvironment.class)} -
    (if more then one instance is found a {@link ConfigurationException} will be thrown</li>
    <li>A call to {@link #getDefaultWebEnvironmentClass(ServletContext)} (default: {@link IniWebEnvironment})</li>
</ul>

@param servletContext current servlet context
@param servletContext the {@code servletContext} to query the {@code ENVIRONMENT_ATTRIBUTE_KEY} property from
@return the WebEnvironment implementation class to use
@return the {@code WebEnvironment} to be used
@see #ENVIRONMENT_CLASS_PARAM
web/src/main/java/org/apache/shiro/web/env/EnvironmentLoader.java