小编Chr*_*ris的帖子

在自定义注释的Aspect中传递方法参数

我正在尝试使用类似的东西org.springframework.cache.annotation.Cacheable:

自定义注释:

@Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    public @interface CheckEntity {
        String message() default "Check entity msg";
        String key() default "";
    }
Run Code Online (Sandbox Code Playgroud)

方面:

@Component
@Aspect
public class CheckEntityAspect {
    @Before("execution(* *.*(..)) && @annotation(checkEntity)")
    public void checkEntity(JoinPoint joinPoint, CheckEntitty checkEntity) {
        System.out.println("running entity check: " + joinPoint.getSignature().getName());
    }
}
Run Code Online (Sandbox Code Playgroud)

服务:

@Service
@Transactional
public class EntityServiceImpl implements EntityService {

    @CheckEntity(key = "#id")
    public Entity getEntity(Long id) {
        return new Entity(id);
    }
}    
Run Code Online (Sandbox Code Playgroud)

我的IDE(IntelliJ)没有看到任何与key = "#id"使用有关的特殊情况,与使用Cacheable不同颜色而不是纯文本的类似用法相比.我提到IDE部分只是作为一个提示,如果有帮助,看起来IDE预先知道这些注释或它只是意识到我的例子中不存在的一些连接.

checkEntity.key中的值为"#id"而不是预期的数字.我尝试使用ExpressionParser但可能不是以正确的方式. …

spring annotations aspectj spring-el

12
推荐指数
2
解决办法
8081
查看次数

标签 统计

annotations ×1

aspectj ×1

spring ×1

spring-el ×1