Tried below example but it's not working with spring.Getting err in editor like "call pointcut designator isn't supported by Spring".
https://dzone.com/articles/enforcing-common-log-format
Any code example would be appreciated.
Tried below example but it's not working with spring.Getting err in editor like "call pointcut designator isn't supported by Spring".
https://dzone.com/articles/enforcing-common-log-format
Any code example would be appreciated.
There are many ways to do this, here is 1.
1) Create an annotation to add to classes/methods that need logging added:
@Documented
@Target(ElementType.METHOD)
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface LogExecution {
}
2) Create an aspect to do the logging:
@Aspect
@Component
public class LogAspect {
private List<String> messages = new ArrayList<>();
@Around("@annotation(hello.LogExecution)")
public Object handelLogging(ProceedingJoinPoint joinPoint) throws Throwable {
Object proceed = null;
try {
// log before
proceed = joinPoint.proceed();
// log after
}
catch (Exception e) {
// log exception
throw e;
}
return proceed;
}
}
Working example here
It sounds like you don't have Aspect J correctly configured.
See the answer to this question for the correct setup:
Spring + AspectJ weaving for java 8 using aspectj-maven-plugin
After that, spring should recognize your pointcuts
The canonical way to use AspectJ from within Spring applications as described by the manual is to use AspectJ load-time weaving (LTW). It does not make sense to weave code into Spring or Java EE binaries and create new JARs etc., so IMO source or binary compile-time weaving is not an option if you want to target 3rd party code. Instead, a dynamic Java weaving agent as described in the manual chapter I linked to above.
Having said that, it was just a reply to the AOP-related suggestions I read about here. It would work the way I described it, but I am happy the OP has solved his problems by means of Mapped Diagnostic Context already.