NutzCN Logo
问答 在service中使用@Async 创建对象时报错
发布于 14天前 作者 wx_1410jsvo2dfu2a7f8mda 142 次浏览 复制 上一个帖子 下一个帖子
标签:
@IocBean
public class AsyncService {
    @Inject
    protected Dao dao;

    @Async
    public Future<List<Map<String, Object>>> getGantry(String fitPath) {
        List<Map<String, Object>> data = new ArrayList<>();
        if (!fitPath.isEmpty()) {
            String[] pathList = fitPath.split("\\|");
            for (String path : pathList) {
                String sqlStr = "select * from GANTRY_TABLE where TOLLINTERVALS = @path and length(lat) > 0 and length(lng) > 0 and  ROWNUM=1 and lat <>'22.123456' and lng <>'22.123456'";
                Sql sql = Sqls.create(sqlStr);
                sql.params().set("path", path);
                sql.setCallback(Sqls.callback.map());
                dao.execute(sql);
                Map<String, Object> dataMap = (Map<String, Object>) sql.getResult();
                if (dataMap != null) {
                    data.add(dataMap);
                }
            }
        }
        return new AsyncResult<>(data);
    }
}
package com.nmgs.module;

import com.nmgs.entity.EvaSionData;
import com.nmgs.service.AsyncService;
import org.nutz.dao.Dao;
import org.nutz.dao.QueryResult;
import org.nutz.dao.pager.Pager;
import org.nutz.integration.quartz.QuartzManager;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.adaptor.JsonAdaptor;
import org.nutz.mvc.annotation.AdaptBy;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

@IocBean
@At("/EvaSionData")
@Ok("json:{locked:'password|salt',ignoreNull:true}")
public class EvaSionDataModule {
    @Inject
    private QuartzManager quartzManager;
    @Inject
    protected Dao dao;
    @Inject
    protected AsyncService asyncService;
    @At
    @Ok("json")
    @AdaptBy(type = JsonAdaptor.class)
    public Object getEvaSionDataList(@Param("..") Map<String, Object> params) {
        Integer pageNum = (Integer) params.get("pageNum");
        Integer pageSize = (Integer) params.get("pageSize");
        Pager pager = dao.createPager(pageNum, pageSize);
//        Cnd where = Cnd.where("", "", "");
        List<EvaSionData> list = dao.query(EvaSionData.class, null, pager);
        pager.setRecordCount(dao.count(EvaSionData.class));
        return new QueryResult(list, pager);
    }

    @At
    @Ok("json")
    public Object getInfo(@Param("..") Map<String, Object> params) throws ExecutionException, InterruptedException {
        String fitPath=params.get("fitPath")==null?"":params.get("fitPath").toString();
        String divPath=params.get("divPath")==null?"":params.get("divPath").toString();
        Future<List<Map<String,Object>>> fitGantryF= asyncService.getGantry(fitPath);
        Future<List<Map<String,Object>>>divGantryF= asyncService.getGantry(divPath);
        Map<String,Object> map=new HashMap<>();
        map.put("fitGantry",fitGantryF.get());
        map.put("divGantry",divGantryF.get());
        return map;
    }
}

org.nutz.ioc.IocException: IocBean[evaSionDataModule] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:153)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:56)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)
	at com.nmgs.Filter.WebCrossOriginFilter.doFilter(WebCrossOriginFilter.java:60)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:168)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:481)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:130)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:670)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:390)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:926)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1790)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: IocBean[evaSionDataModule] fail at field=[asyncService]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	... 36 common frames omitted
Caused by: org.nutz.ioc.IocException: IocBean[asyncService] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:153)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 38 common frames omitted
Caused by: java.lang.NoSuchMethodError: java.lang.invoke.MethodHandles$Lookup.defineClass([B)Ljava/lang/Class;
	at org.nutz.lang.reflect.ReflectTool.defineClass(ReflectTool.java:74)
	at org.nutz.lang.reflect.ReflectTool.defineClass(ReflectTool.java:66)
	at org.nutz.aop.DefaultClassDefiner.define(DefaultClassDefiner.java:25)
	at org.nutz.aop.asm.AsmClassAgent.generate(AsmClassAgent.java:35)
	at org.nutz.aop.AbstractClassAgent.define(AbstractClassAgent.java:56)
	at org.nutz.aop.AbstractClassAgent.define(AbstractClassAgent.java:43)
	at org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:95)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:101)
	... 41 common frames omitted
1 回复

异步方法应该是 void,怎么会有返回值,想啥呢?。。

添加回复
请先登陆
回到顶部