java.lang.IllegalArgumentException:接口 org.jboss.seam.persistence.EntityManagerProxy 在类加载器中不可见

发布于 2024-10-17 07:23:18 字数 1636 浏览 11 评论 0原文

我遇到了一个非常奇怪的错误,我无法理解。 简而言之:我有一个 ImporterBean,它应该读取 xml 文件然后执行操作。 该 ImporterBean 是由 ImporterKicker“启动”的,但是当我启动应用程序时 ImporterBean 类中的 ApplicationBean 和 EntityManager 为 null。他们是 没有注入到那个豆子中。在 KickerBean 中,ImporterBean 和 ApplicationBean 已正确注入。

请参阅下面的代码,请告诉我我做错了什么(使用seam SEAM 2.2.1.CR2)。

@SuppressWarnings({"UnusedDeclaration"})
@Name("importerBean")
@AutoCreate
public class ImporterBean {

private static final FilenameFilter ONLY_XML_FILES = (FilenameFilter) new SuffixFileFilter(".xml");
public static final String IN_DIR = "IN";
public static final String ERROR_DIR = "ERROR";
public static final String PROCESSED_DIR = "PROCESSED";

@In(create = true)
public ApplicationBean applicationBean;

@In
private EntityManager entityManager;


@Asynchronous
@Transactional
public void runImport(@Duration long firstStart, @IntervalDuration long startTimer) {
    log.info("<118100>");
    File inDir = Doing some file stuff...
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

/**
 * Inner class bean to kick the background tasks.
 */
@Startup
@Scope(APPLICATION)
@Name("importerKicker")
public static class ImporterKicker {


    @In(create = true)
    public ImporterBean importerBean;

    @In(create = true)
    public ApplicationBean applicationBean;

    @Create
    public void scheduleOptimizer() {
        final int interval = applicationBean.getImporter118checkInterval();
        if (interval != 0) {

            importerBean.runImport(30 * MILLIS_PER_SECOND, interval * MILLIS_PER_SECOND);
        } else {
        }
    }

}

}

I have run into a pretty strange error that I can't get my head around.
In short: I have an ImporterBean that should read an xml file and then do stuff.
That ImporterBean is "kickstarted" by a ImporterKicker, but when I start the app
the ApplicationBean and EntityManager in the ImporterBean class are null. They are
not injected into that bean. In the KickerBean the ImporterBean and ApplicationBean are injected properly.

See code below and please tell me what I'm doing wrong(Using seam SEAM 2.2.1.CR2).

@SuppressWarnings({"UnusedDeclaration"})
@Name("importerBean")
@AutoCreate
public class ImporterBean {

private static final FilenameFilter ONLY_XML_FILES = (FilenameFilter) new SuffixFileFilter(".xml");
public static final String IN_DIR = "IN";
public static final String ERROR_DIR = "ERROR";
public static final String PROCESSED_DIR = "PROCESSED";

@In(create = true)
public ApplicationBean applicationBean;

@In
private EntityManager entityManager;


@Asynchronous
@Transactional
public void runImport(@Duration long firstStart, @IntervalDuration long startTimer) {
    log.info("<118100>");
    File inDir = Doing some file stuff...
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

/**
 * Inner class bean to kick the background tasks.
 */
@Startup
@Scope(APPLICATION)
@Name("importerKicker")
public static class ImporterKicker {


    @In(create = true)
    public ImporterBean importerBean;

    @In(create = true)
    public ApplicationBean applicationBean;

    @Create
    public void scheduleOptimizer() {
        final int interval = applicationBean.getImporter118checkInterval();
        if (interval != 0) {

            importerBean.runImport(30 * MILLIS_PER_SECOND, interval * MILLIS_PER_SECOND);
        } else {
        }
    }

}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执妄 2024-10-24 07:23:18

由于您使用的是异步调用,因此您不能像在事件范围组件中那样使用注入。

相反,在异步方法中写入:

@Asynchronous
@Transactional
public void runImport(@Duration long firstStart, @IntervalDuration long startTimer) {
    EntityManager entityManager = (EntityManager) Component.getInstance("entityManager");
    ApplicationBean applicationBean = (ApplicationBean) Component.getInstance("applicationBean",true);
    log.info("<118100>");
    File inDir = Doing some file stuff...
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Since you are using an Asynchronous call, you cannot use injections like that in an event scoped component.

Instead inside the Asyncrhonous method write:

@Asynchronous
@Transactional
public void runImport(@Duration long firstStart, @IntervalDuration long startTimer) {
    EntityManager entityManager = (EntityManager) Component.getInstance("entityManager");
    ApplicationBean applicationBean = (ApplicationBean) Component.getInstance("applicationBean",true);
    log.info("<118100>");
    File inDir = Doing some file stuff...
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文