我一直在阅读,但是只发现了很老的帖子,我很想知道现在是否可以在接口方法中使用AOP切入点
@IHandler
public interface SpiHandler extends SpiExtensions {
@SpiExtension
Future<Either<ErrorPayload, EntityPayLoad>> getEntity(String condition);
}
这是我的注释
@Target({ ElementType.METHOD })
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface SpiExtension {
}
这是Aspect类
@Aspect
public class ServiceLoaderAspect {
@Around(value = "@annotation(spiExtension)")
public Object aroundSourceMethod(ProceedingJoinPoint joinPoint, SpiExtension spiExtension) throws Throwable {
ServiceLoaderAspect.aroundSourceMethod(joinPoint, spiExtension);
return joinPoint.proceed();
}
}
我使用的版本是
org.aspectj:aspectjweaver:1.8.5
我的Spring配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="serviceLoader" class="com.spi.aspect.ServiceLoaderAspect"/>
<context:component-scan base-package="com.spi.aspect" />
</beans>