or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

advice-interceptors.mdaspectj-integration.mdauto-proxy.mdcore-abstractions.mdindex.mdpointcuts.mdproxy-creation.mdtarget-sources.md
tile.json

tessl/maven-org-springframework--spring-aop

Spring AOP module providing aspect-oriented programming capabilities for the Spring Framework

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.springframework/spring-aop@6.2.x

To install, run

npx @tessl/cli install tessl/maven-org-springframework--spring-aop@6.2.0

index.mddocs/

Spring AOP

Spring AOP provides comprehensive aspect-oriented programming capabilities for the Spring Framework, enabling developers to implement cross-cutting concerns such as logging, security, transaction management, and monitoring in a modular and reusable way. It offers both programmatic and declarative approaches to AOP through proxy-based interception, support for AspectJ integration, method-level and class-level pointcut expressions, and a rich set of advice types.

Package Information

  • Package Name: org.springframework:spring-aop
  • Package Type: Maven
  • Language: Java
  • Installation:
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
      <version>6.2.8</version>
    </dependency>

Core Imports

import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.Pointcut;
import org.springframework.aop.PointcutAdvisor;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.aop.Advice;

Basic Usage

import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.NameMatchMethodPointcut;
import org.aopalliance.intercept.MethodInterceptor;

// Create an interceptor for logging
MethodInterceptor loggingInterceptor = invocation -> {
    System.out.println("Before method: " + invocation.getMethod().getName());
    Object result = invocation.proceed();
    System.out.println("After method: " + invocation.getMethod().getName());
    return result;
};

// Create a pointcut that matches methods by name
NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
pointcut.setMappedName("businessMethod");

// Create an advisor combining pointcut and advice
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(pointcut, loggingInterceptor);

// Create proxy factory and configure it
ProxyFactory factory = new ProxyFactory(targetObject);
factory.addAdvisor(advisor);

// Create and use the proxy
MyBusinessInterface proxy = (MyBusinessInterface) factory.getProxy();
proxy.businessMethod(); // Logging will occur around the method call

Architecture

Spring AOP is built on a layered architecture of key components:

  • Advice: The action taken at a particular join point (before, after, around, etc.)
  • Pointcut: Defines where advice should be applied (method patterns, class filters)
  • Advisor: Combines advice with pointcut to determine when and where to apply the advice
  • Proxy: Runtime object that intercepts method calls and applies advice
  • Target Source: Manages access to target objects and their lifecycle

The framework integrates with both AOP Alliance standard interfaces and AspectJ for maximum flexibility and interoperability.

Capabilities

Core AOP Abstractions

Fundamental interfaces and classes for pointcuts, advisors, and advice types. These form the foundation of Spring's AOP system and provide the basic building blocks for aspect-oriented programming.

public interface Pointcut {
    ClassFilter getClassFilter();
    MethodMatcher getMethodMatcher();
    Pointcut TRUE = TruePointcut.INSTANCE;
}

public interface Advisor {
    Advice getAdvice();
    boolean isPerInstance();
    Advice EMPTY_ADVICE = new Advice() {};
}

public interface PointcutAdvisor extends Advisor {
    Pointcut getPointcut();
}

Core AOP Abstractions

Proxy Creation and Management

ProxyFactory and related classes for creating AOP proxies programmatically, including configuration options for different proxy strategies and target source management.

public class ProxyFactory extends ProxyCreatorSupport {
    public ProxyFactory();
    public ProxyFactory(Object target);
    public ProxyFactory(Class<?>... proxyInterfaces);
    public Object getProxy();
    public Object getProxy(ClassLoader classLoader);
    public static <T> T getProxy(Class<T> proxyInterface, Interceptor interceptor);
}

Proxy Creation

AspectJ Integration

Support for AspectJ pointcut expressions, @AspectJ annotations, and aspect instance management, providing seamless integration with AspectJ weaving capabilities.

public class AspectJExpressionPointcut implements ClassFilter, MethodMatcher, Pointcut {
    public void setExpression(String expression);
    public String getExpression();
    public boolean matches(Class<?> clazz);
    public boolean matches(Method method, Class<?> targetClass);
}

public class AspectJProxyFactory extends ProxyCreatorSupport {
    public void addAspect(Object aspectInstance);
    public void addAspect(Class<?> aspectClass);
    public <T> T getProxy();
}

AspectJ Integration

Auto-Proxy Creation

Automatic proxy creation through BeanPostProcessor implementations that analyze beans for advisor applicability and create proxies transparently.

public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
        implements BeanPostProcessor, BeanFactoryAware {
    public void setProxyTargetClass(boolean proxyTargetClass);
    public void setOptimize(boolean optimize);
    public void setFrozen(boolean frozen);
}

public class AnnotationAwareAspectJAutoProxyCreator extends AspectJAwareAdvisorAutoProxyCreator {
    // Automatically creates proxies for @AspectJ annotated classes
}

Auto-Proxy Creation

Pointcut Implementations

Various pointcut implementations for different matching strategies including name-based, regular expression, annotation-based, and composable pointcuts.

public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut {
    public void setMappedName(String mappedName);
    public void setMappedNames(String... mappedNames);
    public void addMethodName(String name);
}

public class ComposablePointcut implements Pointcut, Serializable {
    public ComposablePointcut union(Pointcut other);
    public ComposablePointcut intersection(Pointcut other);
}

Pointcut Implementations

Advice Types and Interceptors

Implementation of different advice types (before, after, around, throws) and method interceptors for cross-cutting concerns like performance monitoring and debugging.

public interface MethodBeforeAdvice extends BeforeAdvice {
    void before(Method method, Object[] args, Object target) throws Throwable;
}

public interface AfterReturningAdvice extends AfterAdvice {
    void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable;
}

public class PerformanceMonitorInterceptor extends AbstractMonitoringInterceptor {
    // Monitors method execution times
}

Advice and Interceptors

Target Source Management

Different target source implementations for managing target object lifecycle, including singleton, prototype, pooled, and thread-local target sources.

public interface TargetSource extends TargetClassAware {
    Class<?> getTargetClass();
    boolean isStatic();
    Object getTarget() throws Exception;
    void releaseTarget(Object target) throws Exception;
}

public class HotSwappableTargetSource implements TargetSource, Serializable {
    public Object swap(Object newTarget) throws IllegalArgumentException;
}

Target Sources

Types

// Core marker interfaces
public interface Advice {
    // Tag interface for all advice types
}

public interface BeforeAdvice extends Advice {
    // Marker interface for before advice
}

public interface AfterAdvice extends Advice {
    // Marker interface for after advice
}

// Filtering interfaces
public interface ClassFilter {
    boolean matches(Class<?> clazz);
    ClassFilter TRUE = TrueClassFilter.INSTANCE;
}

public interface MethodMatcher {
    boolean matches(Method method, Class<?> targetClass);
    boolean isRuntime();
    boolean matches(Method method, Class<?> targetClass, Object... args);
    MethodMatcher TRUE = TrueMethodMatcher.INSTANCE;
}

// Proxy configuration
public class ProxyConfig implements Serializable {
    public void setProxyTargetClass(boolean proxyTargetClass);
    public void setOptimize(boolean optimize);
    public void setOpaque(boolean opaque);
    public void setExposeProxy(boolean exposeProxy);
    public void setFrozen(boolean frozen);
}

// Exception types
public class AopConfigException extends NestedRuntimeException {
    // Thrown when there's a configuration problem with AOP proxy creation
    public AopConfigException(String msg);
    public AopConfigException(String msg, Throwable cause);
}

public class AopInvocationException extends NestedRuntimeException {
    // Thrown when there's a problem with AOP method invocation
    public AopInvocationException(String msg);
    public AopInvocationException(String msg, Throwable cause);
}