tags:

views:

59

answers:

1

I want to be able to do this:

@Controller
@RequestMapping("/#{handlerMappingPaths.security}/*")
public class SecurityController {
  etc

  //for instance, to resuse the value as a base for the folder resolution     
  @Value("#{handlerMappingPaths.security}/")
  public String RESOURCE_FOLDER;

  @RequestMapping(value="/signin-again", method = RequestMethod.GET)
    public String signinAgainHandler() {
        return RESOURCE_FOLDER + "signin_again";
    }
}

this doesn't appear to work now, am I missing something?

A: 

One way you can find out things like this is to have a look yourself. This is an example for eclipse, but it should work similarly for other IDEs:

First of all, make sure you have the sources of the spring libraries you are using. This is easiest if you use maven, using the maven-eclipse-plugin or using m2eclipse.

Then, in Eclipse select Navigate -> Open Type.... Enter the type you are looking for (something like RequestMa* should do for lazy typers like myself). Enter / OK. Now right-click the class name in the source file and select References -> Project. In the search view, all uses of this class or annotation will appear.

One of them is DefaultAnnotationHandlerMapping.determineUrlsForHandlerMethods(Class, boolean), where this code snippet will tell you that expression language is not evaluated:

ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
    public void doWith(Method method) {
        RequestMapping mapping = AnnotationUtils.findAnnotation(
                                     method, RequestMapping.class);
        if (mapping != null) {
            String[] mappedPatterns = mapping.value();
            if (mappedPatterns.length > 0) {
                for (String mappedPattern : mappedPatterns) {
                    // this is where Expression Language would be parsed
                    // but it isn't, as you can see
                    if (!hasTypeLevelMapping && !mappedPattern.startsWith("/")) {
                        mappedPattern = "/" + mappedPattern;
                    }
                    addUrlsForPath(urls, mappedPattern);
                }
            }
            else if (hasTypeLevelMapping) {
                urls.add(null);
            }
        }
    }
}, ReflectionUtils.USER_DECLARED_METHODS);

Remember, it's called Open Source. There's no point in using Open Source Software if you don't try to understand what you are using.

seanizer
thank you for the answer, but please save your disparagement, you have no idea what a poster has tried or not tried-
chrismarx
@chris True, and don't take this personally, either. SO answers are targeted at a larger audience than just the OP. I was making a general observation that was perhaps unjustified in your case
seanizer