Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring AOP建议未得到执行_Java_Maven_Spring Mvc_Spring Aop - Fatal编程技术网

Java Spring AOP建议未得到执行

Java Spring AOP建议未得到执行,java,maven,spring-mvc,spring-aop,Java,Maven,Spring Mvc,Spring Aop,我试图让建议得到执行,但它不起作用。我正在尝试在没有应用程序上下文的情况下完成它 这是我的Rest控制器: package hello; import java.util.concurrent.atomic.AtomicLong; import aspect.exception.GreetingsNotFoundException; import org.springframework.web.bind.annotation.RequestMapping; import org.spring

我试图让建议得到执行,但它不起作用。我正在尝试在没有应用程序上下文的情况下完成它

这是我的Rest控制器:

package hello;

import java.util.concurrent.atomic.AtomicLong;

import aspect.exception.GreetingsNotFoundException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

    @RequestMapping("/greeting")
     public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
        return new Greeting(counter.incrementAndGet(),
                String.format(template, name));
    }
}
方面类:

    @Aspect
//@ComponentScan
public class AfterThrowingException implements ThrowsAdvice {

    // Obtain a suitable logger.
    private static Logger logger = LoggerFactory.getLogger(AfterThrowingException.class);

      @Before("execution(hello.GreetingController.greeting()")
    public void logBefore(JoinPoint joinPoint){
    System.out.println("Inside AfterThrowingException.logBefore()");
}
配置类:

    @Configuration
@EnableAspectJAutoProxy
public class AppConfig {
    @Bean
    public AfterThrowingException afterThrowingException() {
        return new AfterThrowingException();
    }
}    
  • 格式如下:

  • 控制器方法接受参数,但不在定义中

  • 尝试:

  • 您需要在完成@Before通知后继续

      jointPoint.proceed();
    
  • 你的名字不同步

  •  @Before("* execution(hello.GreetingController.greeting(..)")
    
      jointPoint.proceed();