您需要确保在DefaultMethodSecurityExpresssionHandler上设置ApplicationContext。例如:
@Autowiredprivate ApplicationContext context;@Overrideprotected MethodSecurityexpressionHandler expressionHandler() { DefaultMethodSecurityexpressionHandler expressionHandler = new DefaultMethodSecurityexpressionHandler(); expressionHandler.setPermissionevaluator(appPermissionevaluator()); expressionHandler.setApplicationContext(context); return expressionHandler;}另外,更简洁地说,如果您将单个Permissionevaluator定义为Bean,Spring
Security将自动选择它(无需覆盖expressionHandler())。例如:
@Beanpublic Permissionevaluator appPermissionevaluator() { ...}


