0

In my Spring application I have controllers with two annotations:

@Controller - Spring annotation

@AdminPanelController - my annotation

Is it possible change my annotation so I can used if with out the need to place @Controller in addition?

I want that Spring will process my annotation as @Controller annotation.

Haim Raman
  • 10,970
  • 6
  • 43
  • 64
Arthur
  • 2,993
  • 6
  • 37
  • 72

2 Answers2

4

Your question is missing some detailed explanation on your needs, but my assumption is that you do not want to bother putting both your annotation and @Controller on your admin panel controllers. You want Spring-MVC you understand that any @AdminPanelController is-a @Controller.
This is exactly what @RestController annotation in Spring 4.0 any @RestController is-a @Controller (See the source code). So your @AdminPanelController annotation should be similar to the one below

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
public @interface AdminPanelController {
    String value() default "";
}

So although java annotation does not support inheritance in the sense we expect (see Why is not possible to extend annotations in Java?) this will work for spring-mvc thanks to meta-annotation (I tested this with 4.1).

Community
  • 1
  • 1
Haim Raman
  • 10,970
  • 6
  • 43
  • 64
3

I'm reasonably sure that all you need is to annotate the AdminPanelController with @Controller

Lev Kuznetsov
  • 3,235
  • 4
  • 18
  • 33