简体   繁体   中英

How to extend Spring MVC Controller Annotation?

I want the code like this can be woking. How can I do?

@Target(value=ElementType.TYPE)
@Retention(value=RetentionPolicy.RUNTIME)
@Controller
@RequestMapping(value=RSI.DEFAULT_MAPPING + mapping())
public @interface RSI {
  public final static String DEFAULT_MAPPING = "/RSI";
  public String mapping() default "";
}


@RSI(mapping="/XXX")
public class XXXRSI {

Spring uses a number of classes (as beans registered in your MVC configuration) for registering and handling the handler methods you declare in a @Controller class. The two main classes you should look at are RequestMappingHandlerMapping and RequestMappingHandlerAdapter .

They have no built in way to do what you are suggesting. You'd have to extend those types (or write new ones with the appropriate interfaces) and register them instead of the ones above. This is not a trivial task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM