在建议未被执行之前
Before advice is not getting executed
我正在尝试调用之前的建议,但是没有使用定义的切入点执行相同的建议
我在包中有主要应用程序 com.my.ms
@SpringBootApplication
@EnableAspectJAutoProxy
public class TemplateServiceApplication {
public static void main(String[] args) {
SpringApplication.run(TemplateServiceApplication.class, args);
}
}
在包 com.my.ms.tst.advices 中我有之前的建议
@Aspect
public class ValidatingAdvices {
@Before(value = "execution(* com.my.ms.tst.api.*.get*(..))")
public void validateKey(JoinPoint joinPoint) throws Throwable {
System.out.println("Executing the before advice");
}
}
控制器在包com.my.ms.tst.api
@Controller
@RequestMapping("/ts")
public class MainController {
@GetMapping("/check")
public String getTemp() throws IOException {
return "five";
}
}
但是下面的建议没有被执行
您在ValidatingAdvices中添加了@Configuration注解。
@Configuration
@Aspect
public class ValidatingAdvices {
@Before(value = "execution(* com.my.ms.tst.api.*.get*(..))")
public void validateKey(JoinPoint joinPoint) throws Throwable {
System.out.println("Executing the before advice");
}
}
您也可以使用@Component 而不是@Configuration,或者如果您已经使用了@component class 那么没关系,但请确保ValidatingAdvices class 不必使用@Bean。 Click here 更多参考。
@Component // @Configuration
@Aspect
public class ValidatingAdvices {
@Before(value = "execution(* com.my.ms.tst.api.*.get*(..))")
public void validateKey(JoinPoint joinPoint) throws Throwable {
System.out.println("Executing the before advice");
}
}
我正在尝试调用之前的建议,但是没有使用定义的切入点执行相同的建议
我在包中有主要应用程序 com.my.ms
@SpringBootApplication
@EnableAspectJAutoProxy
public class TemplateServiceApplication {
public static void main(String[] args) {
SpringApplication.run(TemplateServiceApplication.class, args);
}
}
在包 com.my.ms.tst.advices 中我有之前的建议
@Aspect
public class ValidatingAdvices {
@Before(value = "execution(* com.my.ms.tst.api.*.get*(..))")
public void validateKey(JoinPoint joinPoint) throws Throwable {
System.out.println("Executing the before advice");
}
}
控制器在包com.my.ms.tst.api
@Controller
@RequestMapping("/ts")
public class MainController {
@GetMapping("/check")
public String getTemp() throws IOException {
return "five";
}
}
但是下面的建议没有被执行
您在ValidatingAdvices中添加了@Configuration注解。
@Configuration
@Aspect
public class ValidatingAdvices {
@Before(value = "execution(* com.my.ms.tst.api.*.get*(..))")
public void validateKey(JoinPoint joinPoint) throws Throwable {
System.out.println("Executing the before advice");
}
}
您也可以使用@Component 而不是@Configuration,或者如果您已经使用了@component class 那么没关系,但请确保ValidatingAdvices class 不必使用@Bean。 Click here 更多参考。
@Component // @Configuration
@Aspect
public class ValidatingAdvices {
@Before(value = "execution(* com.my.ms.tst.api.*.get*(..))")
public void validateKey(JoinPoint joinPoint) throws Throwable {
System.out.println("Executing the before advice");
}
}