001/* 002 * Copyright 2002-2017 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.core.env; 018 019/** 020 * Interface indicating a component that contains and exposes an {@link Environment} reference. 021 * 022 * <p>All Spring application contexts are EnvironmentCapable, and the interface is used primarily 023 * for performing {@code instanceof} checks in framework methods that accept BeanFactory 024 * instances that may or may not actually be ApplicationContext instances in order to interact 025 * with the environment if indeed it is available. 026 * 027 * <p>As mentioned, {@link org.springframework.context.ApplicationContext ApplicationContext} 028 * extends EnvironmentCapable, and thus exposes a {@link #getEnvironment()} method; however, 029 * {@link org.springframework.context.ConfigurableApplicationContext ConfigurableApplicationContext} 030 * redefines {@link org.springframework.context.ConfigurableApplicationContext#getEnvironment 031 * getEnvironment()} and narrows the signature to return a {@link ConfigurableEnvironment}. 032 * The effect is that an Environment object is 'read-only' until it is being accessed from 033 * a ConfigurableApplicationContext, at which point it too may be configured. 034 * 035 * @author Chris Beams 036 * @since 3.1 037 * @see Environment 038 * @see ConfigurableEnvironment 039 * @see org.springframework.context.ConfigurableApplicationContext#getEnvironment() 040 */ 041public interface EnvironmentCapable { 042 043 /** 044 * Return the {@link Environment} associated with this component 045 * (may be {@code null} or a default environment). 046 */ 047 Environment getEnvironment(); 048 049}