- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要从某个方面的 joinPoint 获取像 POST/PATCH/GET/etc 这样的 http 方法。
@Before("isRestController()")
public void handlePost(JoinPoint point) {
// do something to get for example "POST" to use below
handle(arg, "POST", someMethod::getBeforeActions);
}
从point.getThis.getClass()
,我得到了该调用被拦截的 Controller 。然后,如果我从中获取方法和注释。这应该足够好了吧?
所以point.getThis().getClass().getMethod(point.getSignature().getName(),???)
我如何获取类参数类型?
最佳答案
以下代码获取所需的 Controller 方法注释详细信息
@Before("isRestController()")
public void handlePost(JoinPoint point) {
MethodSignature signature = (MethodSignature) point.getSignature();
Method method = signature.getMethod();
// controller method annotations of type @RequestMapping
RequestMapping[] reqMappingAnnotations = method
.getAnnotationsByType(org.springframework.web.bind.annotation.RequestMapping.class);
for (RequestMapping annotation : reqMappingAnnotations) {
System.out.println(annotation.toString());
for (RequestMethod reqMethod : annotation.method()) {
System.out.println(reqMethod.name());
}
}
// for specific handler methods ( @GetMapping , @PostMapping)
Annotation[] annos = method.getDeclaredAnnotations();
for (Annotation anno : annos) {
if (anno.annotationType()
.isAnnotationPresent(org.springframework.web.bind.annotation.RequestMapping.class)) {
reqMappingAnnotations = anno.annotationType()
.getAnnotationsByType(org.springframework.web.bind.annotation.RequestMapping.class);
for (RequestMapping annotation : reqMappingAnnotations) {
System.out.println(annotation.toString());
for (RequestMethod reqMethod : annotation.method()) {
System.out.println(reqMethod.name());
}
}
}
}
}
注意:此代码可以进一步优化。作为示例共享以展示可能性
关于java - 从 joinPoint 获取 HTTP 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59742937/
这是我第一次接触 AOP。我有一个带有一个方面的 spring-boot 应用程序,一个记录器。搜索我得出的结论是 @Around 方法在方法之前和之后执行(我只在一种方法中调用它),这是对的吗? 在
假设我有这个方法: public void exampleMethod(String myString, Integer myInteger, Object myObject){} 如果我有一个方面
我正在使用 Java Spring Mvc 和 Spring AOP 从用户那里查找参数名称。 我有一个 Controller ,它从用户那里获取参数并调用服务。 我有一个方面在服务之前运行。 该方面
AspectJ的JoinPoint是一个接口(interface),ProceedingJoinPoint也是一个扩展Joinpoint的接口(interface)。 但是,当我在某个方面使用它们时,
我在 Spring 使用 AOP: 我写了一个注释 @Retention(RetentionPolicy.RUNTIME) public @interface TestAnnotation { } 我
我正在学习面向方面的编程概念和 Spring AOP。我无法理解切入点和连接点之间的区别——它们对我来说似乎都是一样的。切入点是您应用建议的地方,而连接点也是我们可以应用建议的地方。那有什么区别呢?
我需要从某个方面的 joinPoint 获取像 POST/PATCH/GET/etc 这样的 http 方法。 @Before("isRestController()") public voi
我有以下建议代码: @Around("annotatedMethod()") public Object aroundGetPanel(ProceedingJoinPoint join
LoggingAspect.java @Around("allGenericAppServiceImplMethods()") public Object LoggingAdvice(Proceedi
我有一个应用程序(使用注释的 Spring 4 MVC+Hibernate 4+MySQL+Maven 集成示例),使用基于注释的配置将 Spring 与 Hibernate 集成。如果可能的话,我想
我正在使用 maven 来构建我的项目。之前编译成功。当我执行 mvn clean install 时,它开始出现错误。 [ERROR] classpath error: unable to find
(标题不是最好的,但我找不到一个好的方式来表达以下问题) 给定 @Aspect @Component class MyAspect { @Autowired private MyService s
我想检索调用特定方法的调用方法。 示例: 我考虑的方法: public void methodA(int a, int b){...} 在测试方法和程序本身中调用 @Test public void
我正在处理Spring AOP,我的代码是这样的 - @Component public class MyClass implements MethodInterceptor{ @Overri
我有一个带有 @Around 注释的简单方面(见下文)。当应用程序不使用响应式范例时,此方面有效。但是当应用程序返回 Mono 或 Flux 时就无法正常工作。 我需要获取从方法返回的对象来生成 JS
同时使用@Around 方面和Spring 引导。在 joinPoint 执行之前创建变量、在 joinPoint 执行期间使其可用以收集其中的数据以及在 joinPoint 执行之后使用变量中收集的
我是一名优秀的程序员,十分优秀!