我正在尝试为springs @ PreAuthorize注释实现自定义授权功能。
代码如下:
控制器
@PreAuthorize("@localBeanChecker.isAdmin()")
@GetMapping("/contents")
public List<Content> index() {
return manageContentService.fetchAllContent();
}
LocalBeanChecker
package project.configuration;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
@Component(value = "localBeanChecker")
public class LocalBeanChecker {
public boolean isAdmin() {
return false;
}
}
当我向/ contents请求时失败。
错误
org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method isAdmin() cannot be found on project.configuration.LocalBeanChecker type
我想念什么吗?