Open smarek opened 12 years ago
OK, now when digging little bit deeper I found this, which means, any of CustomCondition cannot be used separately without defining @RequestMapping
on same level (Method, Type).
I think this is bad approach, if that does mean we cannot use eg. RoleMapping on @Controller and @RequestMapping to define path of each method absolutely.
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.class (https://github.com/SpringSource/spring-framework/blob/master/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java)
/**
* Uses method and type-level @{@link RequestMapping} annotations to create
* the RequestMappingInfo.
*
* @return the created RequestMappingInfo, or {@code null} if the method
* does not have a {@code @RequestMapping} annotation.
*
* @see #getCustomMethodCondition(Method)
* @see #getCustomTypeCondition(Class)
*/
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
RequestMappingInfo info = null;
RequestMapping methodAnnotation = AnnotationUtils.findAnnotation(method, RequestMapping.class);
if (methodAnnotation != null) {
RequestCondition<?> methodCondition = getCustomMethodCondition(method);
info = createRequestMappingInfo(methodAnnotation, methodCondition);
RequestMapping typeAnnotation = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
if (typeAnnotation != null) {
RequestCondition<?> typeCondition = getCustomTypeCondition(handlerType);
info = createRequestMappingInfo(typeAnnotation, typeCondition).combine(info);
}
}
return info;
}
The proper workaround now is to use empty @RequestMapping
, but I wonder if this is the nice way to do it:
example
@Controller
@PreAuthorize("hasAuthority('ROLE_MANAGER')")
@RequestMapping
@SubdomainMapping(value = { "managers", "www" })
public class ManagerController {
Can you please modify the provided example of @RoleMapping to provide @Controller with role mapping?
Simply using this, does not work: