一、调用类:
@Autowired
CommonService commonService;
...
try {
String platformId = "";
Map<String, Object> parasMap = new HashMap<String, Object>();
// 注意此字符串必须是真实路径,就是带包名的类路径,包名.类名
String classPath = "com.xxx.MyClass";
Class stuClass = Class.forName(classPath);
Object obj = stuClass.newInstance();
// 此例为:调用类方法,方法的入参1(String类型),方法的入参2(Map类型),方法的入参3(service层类)
Method md = stuClass.getDeclaredMethod("synchroProject", String.class, Map.class, CommonService.class);
// 承上相应值:类实例,方法的入参1(String类型),方法的入参2(Map类型),方法的入参3(service层类)
md.invoke(obj, platformId, parasMap, commonService);
} catch (Exception e) {
e.printStackTrace();
}
二、com.xxx.MyClass类:
public synchronized void synchroProject(String platformId, Map<String, Object> parasMap, CommonService commonService)
throws BusinessException, DBException, Exception {
// 业务逻辑
}