应用程序或会话不适用于后台线程

时间:2018-12-06 03:29:44

标签: spring spring-annotations

开发环境

java + Wicket +休眠+ Spring

说明

从ui调用

@Async方法中的Web会话不可用。

我在页面中有一个按钮,当用户单击该按钮时,它会调用“ importContactInBackground”方法。

Spring xml配置

<task:annotation-driven executor="commonTaskExecutor"/>
<task:executor id="commonTaskExecutor" pool-size="5-10" queue-capacity="20"/>

@bean类中的@Async方法

@Async
public void importContactInBackground(File file)
{
    importService.import(file);
    CustomSession customSession = (CustomSession)Session.get();//throws exception
    LOGGER.info("Contacts are imported by {}", customSession.getUsername());
}

异常

org.apache.wicket.WicketRuntimeException: There is no application attached to current thread commonTaskExecutor-2
at org.apache.wicket.Application.get(Application.java:235)
at org.apache.wicket.Session.get(Session.java:175)

1 个答案:

答案 0 :(得分:0)

我在这里working-with-background-jobs找到了一些东西,