@Autowired
WebApplicationContext wac;
...省略
try {
Class<?> clazz = wac.getBean("smsEvent").getClass();
Class[] classes = null;
if (args != null && args.length != 0){
List<Object> parameters = Arrays.asList(args);
classes = new Class[parameters.size()];
for (int i = 0; i < parameters.size(); i++) {
classes[i] = parameters.get(i).getClass();
}
}
Method method = clazz.getMethod(methodName, classes);
Object reObject=method.invoke(wac.getBean("smsEvent"), args);
return reObject;
} catch (Exception e) {
e.printStackTrace();
logger.info("ExecutionTask.executionMethod:出错了...");
return "error";
}
SpringBoot反射@Resource和@Autowired不生效处理
最新推荐文章于 2024-09-03 11:24:14 发布