我们可以在其他注释中使用spring表达式(spel)吗?

chr*_*arx 7 java spring

我希望能够这样做:

@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";
    }
}
Run Code Online (Sandbox Code Playgroud)

这似乎现在不起作用,我错过了什么?

chr*_*arx -3

@Sean 回答了 spring 是否支持这一点的问题,但我也想回答一般情况下如何在使用注释时不重复配置的问题。事实证明,使用静态导入可以实现这一点,如下所示:

import static com.test.util.RequestMappingConstants.SECURITY_CONTROLLER_PATH

@Controller
@RequestMapping("/" + SECURITY_CONTROLLER_PATH + "/*")
public class SecurityController {
  etc

  //for instance, to resuse the value as a base for the folder resolution     
  public String RESOURCE_FOLDER = SECURITY_CONTROLLER_PATH + "/";

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