解决方法:
在使用反射的类中注入 ApplicationContext,
通过applicationContext.getBea(cls); 从spring中获取bean
@Autowired
private ApplicationContext applicationContext;
Class<?> cls = Class.forName("xxx.xxx.xxx.xxx.classname");
Object bean = applicationContext.getBean(cls);
Method method = cls.getMethod(methodName, class<?>parameterTypes);
Object invoke = method.invoke(bean, parameter);
————————————————
版权声明:本文为优快云博主「w宁静致远」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/wsh_ningjing/article/details/90632952