0
我已經使用Spring MVC的自定義註解implemetation
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping .
它的正常工作一個自定義註解,有時候它看起來昂貴的所有方法調用,控制轉到註釋實現類。 我希望控件將僅用於已聲明自定義註釋的那些方法的實現類。有人可以告訴我怎麼做到這一點。 我已經做了如下。
在web.xml: -
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
在controller.xml: -
<bean id="myInterceptor" class="com.common.annotation.MyInterceptor"/>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="interceptors">
<list>
<ref bean="myInterceptor"/>
</list>
</property>
</bean>
在Annotaion類: -
@Target({ElementType.METHOD,ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
boolean checkAuth() default true;
}
使用它作爲: -
@RequestMapping(value = "/user", method = RequestMethod.GET)
@MyAnnotation(checkAuth=true)
public ModelAndView forUser() {........
有人可以請建議。
你的意思,你只希望你實現自定義攔截器被稱爲對於那些標註了'@ MyAnnotation'的方法呢? –
是尼爾,我正在尋找那個。 –
爲什麼你認爲目前的方法成本高? –