Created
August 9, 2018 02:56
-
-
Save guozi/9f33bb9b4a81c22da827c1714498513c to your computer and use it in GitHub Desktop.
BeanPostProcessor Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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