I have a little experience with java Servlets and JSP, but i worked with Spring. In Spring we have interface named BeanPostProcessor. I used this interface implementation to create custom annotations. Code example
public class InjectRandomIntAnnotationBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String string) throws BeansException {
Field[] fields = bean.getClass().getDeclaredFields();
for (Field field : fields) {
InjectRandomInt annotation = field.getAnnotation(InjectRandomInt.class);
if (annotation != null) {
int min = annotation.min();
int max = annotation.max();
Random r = new Random();
int i = min + r.nextInt(max - min);
field.setAccessible(true);
ReflectionUtils.setField(field, bean, i);
}
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object o, String string) throws BeansException {
return o;
}
}
When i begin working with servlets i mentioned this annotation @WebServlet(urlPatterns = "/user/login")
The question is: is it any functional in servlets that is similar with BeanPostProcessor in Spring and where is this annotation @WebServlet injected?
Example: I mean annotations in Spring are injected with BeanPostProcessor, for examle annotation @AutoWired is declared by AutoWiredAnnotationBeanPostProcessor class, but where the annotation @WebServlet is injected(or declared)