org.springframework.aop.framework.AopContext Maven / Gradle / Ivy
/*
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.framework;
import org.springframework.core.NamedThreadLocal;
import org.springframework.lang.Nullable;
/**
* Class containing static methods used to obtain information about the current AOP invocation.
*
* The {@code currentProxy()} method is usable if the AOP framework is configured to
* expose the current proxy (not the default). It returns the AOP proxy in use. Target objects
* or advice can use this to make advised calls, in the same way as {@code getEJBObject()}
* can be used in EJBs. They can also use it to find advice configuration.
*
*
Spring's AOP framework does not expose proxies by default, as there is a performance cost
* in doing so.
*
*
The functionality in this class might be used by a target object that needed access
* to resources on the invocation. However, this approach should not be used when there is
* a reasonable alternative, as it makes application code dependent on usage under AOP and
* the Spring AOP framework in particular.
*
* @author Rod Johnson
* @author Juergen Hoeller
* @since 13.03.2003
*/
public final class AopContext {
/**
* ThreadLocal holder for AOP proxy associated with this thread.
* Will contain {@code null} unless the "exposeProxy" property on
* the controlling proxy configuration has been set to "true".
* @see ProxyConfig#setExposeProxy
*/
private static final ThreadLocal