什么是覆盖参数的AspectJ声明性语法
之前已经使用注释语法对此进行了回答: Aspectj覆盖方法的参数
但我无法弄清楚如何使用AspectJ声明性语法。 以下应该在方法中的每个字符串前添加“Poop”,但它不会。
public aspect UserInputSanitizerAdvisor { pointcut unSafeString() : execution(@RequestMapping * * (..)); Object around() : unSafeString() { //thisJoinPoint.getArgs(); //proceed(); System.out.println("I'm Around"); Object[] args = thisJoinPoint.getArgs(); if (args != null) { for (int i = 0; i < args.length; i++) { Object o = args[i]; if (o != null && o instanceof String) { String s = (String) o; args[i] = "poop: " + s; } } } return proceed(); } }
我无法弄清楚如何给出“继续()”所有的论点。
我得到了注释版本:
@SuppressWarnings("unused") @Aspect public class UserInputSanitizerAdivsor { @Around("execution(@RequestMapping * * (..))") public Object check(final ProceedingJoinPoint jp) throws Throwable { Object[] args = jp.getArgs(); if (args != null) { for (int i = 0; i < args.length; i++) { Object o = args[i]; if (o != null && o instanceof String) { String s = (String) o; args[i] = UserInputSanitizer.sanitize(s); } } } return jp.proceed(args); } }
现在我对所有的Spring MVC控制器都有XSS保护。 我希望得到aspectJ语法。
return thisJoinPoint.proceed(args);
做你想要的?
- 为什么在制作Spring项目时我没有接触到weaver警告?
- 使用Spring IoC和JavaConfig配置AspectJ方面?
- 如何检测/建议Spring Data(JPA)存储库?
- 使用Instrumentation记录未处理的exception
- Spring – slf4J:如何自动记录错误和exception?
- 如何在Spring 3中将@Aspect与@Controller结合起来?
- Spring Boot,使用@Configurable和加载时间编织将@Autowire转换为非托管类
- 为什么Spring AOP不会在运行时编织外部jar?
- AspectJ加载时间编织不能在Spring bean上运行