最近写java多线程时需要调用service,尝试后唯一下方法可行:
以task.java里调用smsStackService内方法testSingleMt()方法为例
1).在resources.groovy内
beans = {
myBean(com.crm.my.company.MyBeanImpl) {
smsStackService = ref("smsStackService")
}
}
2).在com.crm.my.company包下建一个java类MyBeanImpl
public class MyBeanImpl {
public SmsStackService smsStackService;
public void setSmsStackService(SmsStackService smsStack) {
this.smsStackService = smsStack;
}
}
3).task中调用方法
WebApplicationContext ctx;
ctx = WebApplicationContextUtils.getWebApplicationContext(ServletContextHolder.getServletContext());
MyBeanImpl myBeanImpl =(MyBeanImpl)ctx.getBean("myBean");
Object sendResult = myBeanImpl.smsStackService.testSingleMt();
以task.java里调用smsStackService内方法testSingleMt()方法为例
1).在resources.groovy内
beans = {
myBean(com.crm.my.company.MyBeanImpl) {
smsStackService = ref("smsStackService")
}
}
2).在com.crm.my.company包下建一个java类MyBeanImpl
public class MyBeanImpl {
public SmsStackService smsStackService;
public void setSmsStackService(SmsStackService smsStack) {
this.smsStackService = smsStack;
}
}
3).task中调用方法
WebApplicationContext ctx;
ctx = WebApplicationContextUtils.getWebApplicationContext(ServletContextHolder.getServletContext());
MyBeanImpl myBeanImpl =(MyBeanImpl)ctx.getBean("myBean");
Object sendResult = myBeanImpl.smsStackService.testSingleMt();