我们正尝试如下将值注入hasRole()
@PreAuthorize("hasRole(${role.rolename})")
public void method() {}
但它不起作用
还尝试了以下解决方案
@RestController("appVariablesHolder")
public class AppVariablesHolder {
@Value("${role.rolename}")
private String someRole;
public String getSomeRole() {
return this.someRole;
}
}
@PreAuthorize("hasRole(@appVariablesHolder.getSomeRole())")
public void method() {}
但是出现错误
{"exception": { "name":"java.lang.IllegalArgumentException","message":"Failed to evaluate
expression \u0027hasRole(@appVariablesHolder.getSomeRole())\u0027"
}
}
如何在hasRole()方法中将@value作为参数注入?