Created Custom annotation and add annotation at method level and pass value to Spring-Aspect.
springboot: application.properties spring.event.type=TEST
Output: PreHook Value|${spring.event.type}
I am expecting : TEST
Can someone please help how to populate value from properties file and inject to annotation.
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface PreHook {
String eventType();
}
@Aspect
@Component
public class ValidationAOP {
@Before("@annotation(com.example.demo.annotation.PreHook)")
public void doAccessCheck(JoinPoint call) {
System.out.println("ValidationAOP.doAccessCheck");
MethodSignature signature = (MethodSignature) call.getSignature();
Method method = signature.getMethod();
PreHook preHook = method.getAnnotation(PreHook.class);
System.out.println("PreHook Value|" + preHook.eventType());
}
}`
@RestController
public class AddController {
@GetMapping("/")
@PreHook(eventType = "${spring.event.type}")
public String test() {
System.out.println("Testcontroller");
return "Welcome Home";
}
}