1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| @Component @Aspect public class LogAspect implements BeanPostProcessor { @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { ReflectionUtils.doWithFields(bean.getClass(), field -> { ReflectionUtils.makeAccessible(field); if (null != field.getAnnotation(Log.class)){ final Logger log = LoggerFactory.getLogger(bean.getClass()); field.set(bean,log); } }); return bean; } }
|