Is it possible to create a Java annotations equivalent to a Spring MVC @RequestMapping with a predefined set of parameters?
For instance, something that allows me to simply use:
@PostJson("/input")
public Output myMethod(Input input) {
instead of:
@RequestMapping(value = "/input",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE)
public Output myMethod(Input input) {
UPDATE: Let me try to dig a little deeper. AFAIK, Spring seems to be able to handle meta-annotations when scanning for beans. For instance, if I create an annotation, lets say @MyComponent, and annotate it with @Component:
@Component
public @interface MyComponent {
String value() default "";
}
Spring seems able to find beans with @MyComponent and to recognize the parameters (value in this case) in @MyComponent as if they were from @Component
@MyComponent("MyBean")
public class SomeClass {
I've tryed similar tactic with @RequestMapping
@RequestMapping(method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
public @interface PostJson {
String value() default "";
}
The fixed parameters (method an produces) seems to be correct, nonetheless, the variable parameter (value) is ignored.
I am hoping that this is not a @Component specific feature and that I could use it with @RequestMapping.
@Componentdoes not apply to@RequestMapping. As I stated below,@RequestMappingis handled byRequestMappingHandlerMappingwhich does not check for anything else.