Java
- 1 ответ
- 0 вопросов
1
Вклад в тег
mvn install
package com.toster.dao;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Toster {
}
package com.toster.dao;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Aspect
public class TosterAspect {
private static final Logger LOG = LoggerFactory.getLogger(TosterAspect.class);
@Around("execution(* *(..)) && @annotation(tr)")
public Object request(final ProceedingJoinPoint pjp, final Toster tr) throws Throwable {
try {
LOG.info("Invoke {}", pjp.toShortString());
final Object proceed = pjp.proceed();
LOG.info("Return {}", proceed);
return proceed;
} catch (Exception e) {
LOG.error("Error", e);
throw e; //TODO
}
}
}
package com.toster.dao;
import org.aspectj.lang.Aspects;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@Configuration
@EnableAspectJAutoProxy
public class AspectConfiguration {
@Bean
public TosterAspect tosterAspect() {
return Aspects.aspectOf(TosterAspect.class);
}
}