本文共 2119 字,大约阅读时间需要 7 分钟。
c.我把放在定时任务中的整个业务逻辑放入接口中通过httpClient方式调用,这是我当时脑海中第一想到能100%解决的办法,代码如下import org.junit.Before; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; private ApplicationContext applicationContext; @Before public void setUp() throws Exception { applicationContext = new FileSystemXmlApplicationContext("classpath:spring/applicationContext.xml"); } @Test public void testSelectBySelective() { MobileDepartmentTotalService mobileDepartmentTotalService = (MobileDepartmentTotalService)applicationContext.getBean("mobileDepartmentTotalService"); //MobileDepartmentTotal mobileDepartmentTotal = new MobileDepartmentTotal(); Listlist = mobileDepartmentTotalService.selectBySelective(null); System.out.println(list.size()); }
HttpClient httpClient = new HttpClient(); GetMethod getMethod = new GetMethod(url); getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,new DefaultHttpMethodRetryHandler()); try { httpClient.executeMethod(getMethod); ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream in = getMethod.getResponseBodyAsStream(); int len = 0; byte[] buf = new byte[1024]; while((len=in.read(buf))!=-1){ out.write(buf, 0, len); } responseMsg = out.toString("UTF-8"); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { //释放连接 getMethod.releaseConnection(); }
转载地址:http://alaqb.baihongyu.com/