标签:java
className:实现类的名称,包含全路径
functionName:方法名
beanName:beanId,即@Service()中value的值
FwaApplicationUtils.getInstance().getApplicationContext():获取spring_context
代码如下:
Class<?> clz = Class.forName(className);
Object myservice = FwaApplicationUtils.getInstance().getApplicationContext().getBean(beanName);
Method m =null;
if(paramsType.equalsIgnoreCase("map")){
m = clz.getMethod(functionName,Map.class);
Map<String, String> map=new HashMap<String, String>();
map.put("periodId", "201606");
m.invoke(myservice,map);
}else if(paramsType.equalsIgnoreCase("string")){
m = clz.getMethod(functionName,String.class);
String kpiTime="201603";
m.invoke(myservice,kpiTime);
}else{
m = clz.getMethod(functionName);
m.invoke(myservice);
}
通过字符创调用接口中实现类的方法,SpringBean自动注入,
标签:java
原文地址:http://tianjian.blog.51cto.com/3549910/1841581