获取 spring 中的所有 @PreAuthorize List<string>
get all @PreAuthorize List<string> in spring
我试图找出一种方法来从 spring 容器中获取所有预授权注释的列表
假设我有如下内容。
@PreAuthorize("hasPermission(null, 'opetussuunnitelma', 'LUONTI1')")
@PreAuthorize("hasPermission(null, 'opetussuunnitelma', 'LUONTI2')")
@PreAuthorize("hasPermission(null, 'opetussuunnitelma', 'LUONTI3')")
> I need to get that string(hasPermission(null, 'opetussuunnitelma',
> 'LUONTI2')) or at least List<Map> (x=null,y='opetussuunnitelma',
> z='LUONTI1')
我有什么办法可以做到这一点,因为我有 n 个这样的注释,我需要解析所有这些注释字符串并对其进行处理。
为了在 JVM 中加载所有应用程序的 类,您可以尝试 Reflection library, get the loaded beans from Spring 应用程序上下文或手动将它们添加到静态列表。也就是说,没有明确和正确的方法来实现这一目标。
要获取注释,请使用 Java 反射。
更多信息:https://www.geeksforgeeks.org/method-class-getannotation-method-in-java/
public void handleAnnotations(Class c) {
try {
Method[] methods = c.getMethods();
for (Method method : methods) {
PreAuthorize[] annotations = c.getAnnotationsByType(PreAuthorize.class);
// handle annotations
}
}
catch (Exception e) {
// handle exception
}
}
我试图找出一种方法来从 spring 容器中获取所有预授权注释的列表
假设我有如下内容。
@PreAuthorize("hasPermission(null, 'opetussuunnitelma', 'LUONTI1')")
@PreAuthorize("hasPermission(null, 'opetussuunnitelma', 'LUONTI2')")
@PreAuthorize("hasPermission(null, 'opetussuunnitelma', 'LUONTI3')")
> I need to get that string(hasPermission(null, 'opetussuunnitelma',
> 'LUONTI2')) or at least List<Map> (x=null,y='opetussuunnitelma',
> z='LUONTI1')
我有什么办法可以做到这一点,因为我有 n 个这样的注释,我需要解析所有这些注释字符串并对其进行处理。
为了在 JVM 中加载所有应用程序的 类,您可以尝试 Reflection library, get the loaded beans from Spring 应用程序上下文或手动将它们添加到静态列表。也就是说,没有明确和正确的方法来实现这一目标。
要获取注释,请使用 Java 反射。
更多信息:https://www.geeksforgeeks.org/method-class-getannotation-method-in-java/
public void handleAnnotations(Class c) {
try {
Method[] methods = c.getMethods();
for (Method method : methods) {
PreAuthorize[] annotations = c.getAnnotationsByType(PreAuthorize.class);
// handle annotations
}
}
catch (Exception e) {
// handle exception
}
}