Issue
I am looking for a solution for the problem where I can configure the pointcut expressions dynamically by reading from a properties file or database.
for example: @Around("execution(* com.example.updateUser(..))")
in above example, we have hardcoded the expression. I am looking for the solution where I can read
execution(* com.example.updateUser(..)) and then use it in @Around annotation.
I did not come across similar problem on web. Any solution for such problem is highly appreciated. Thank you!!
Solution
You can use schema-based AOP and define the pointcut in classical, old-school XML style. Spring XML config is a text file being read while starting up the application and thus would satisfy your requirement.
If you like to manually wire your pointcut into an aspect, you can do that, too. Whether you define a string variable or field containing the pointcut directly in your application or read the pointcut from a text file, is completely up to you. Search for the terms DefaultPointcutAdvisor
and AspectJExpressionPointcut
in my answer here, somewhere inside the "update 2" and "update 3" parapgraphs. There you will also find a link to a complete sample project.
Answered By - kriegaex
Answer Checked By - Timothy Miller (JavaFixing Admin)