If the EJB is constructed by Spring, then you can use a Spring bean post processor (this is what Spring uses when it performs it's scan).
@Component
public class FooFinder implements BeanPostProcessor {
List<Method> fooMethods = new ArrayList<>();
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
Class<?> targetClass = AopUtils.getTargetClass(bean);
for (Method method : targetClass.getDeclaredMethods()){
for (Annotation annotation : AnnotationUtils.getAnnotations(method)){
if (annotation instanceof Foo){
fooMethods.add(method);
}
}
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
}
Also be warned... be careful about dependency injection into your BeanPostProcessor. You may create problems with the Spring dependency graph, as the BeanPostProcessors must be created first. If you need to register the method with some other bean, make the BeanPostProcessor ApplicationContextAware or BeanFactoryAware, and get the bean that way.