Skip to content

Instantly share code, notes, and snippets.

@guozi
Created August 9, 2018 02:56
Show Gist options
  • Save guozi/9f33bb9b4a81c22da827c1714498513c to your computer and use it in GitHub Desktop.
Save guozi/9f33bb9b4a81c22da827c1714498513c to your computer and use it in GitHub Desktop.
BeanPostProcessor Demo
public class MyListenerProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
Method[] methods = ReflectionUtils.getAllDeclaredMethods(bean.getClass());
if (methods != null) {
for (Method method : methods) {
MyListener myListener = AnnotationUtils.findAnnotation(method, MyListener.class);
// process
}
}
return bean;
}
}
@Service
public class MyService {
@MyListener
public void onMessage(Message msg){
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment