是否可以在 JBoss 定时服务中使用 Seam? [英] Is it possible to use Seam in a JBoss timed service?

查看:15
本文介绍了是否可以在 JBoss 定时服务中使用 Seam?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始编写一些新的 JBoss 定时服务,旨在使用一些现有的接缝组件.但是由于上下文不存在,我似乎无法访问这些组件.除了 JSF 的典型情况之外,是否可以使用它们?

I've started to write some new JBoss timed service that was meant to use some existing seam components. But it seems that I can't access these components because of non-existing contexts. Is it possible to use them other than in the typical situation with JSF?

一个小片段来演示我想要做什么...

A little snippet to demonstrate what I want to do...

@Service
public class MyService extends DefaultTimedService implements TimedObject, DefaultServiceInterface {
    @Timeout
    public void ejbTimeout(Timer timer) {
        MyInterface loader = (MyInterface) Component.getInstance(MyInterface.SEAM_NAME, true);
        // throws no context!
    }
}

例如抛出以下异常:

java.lang.IllegalStateException: No application context active
    at org.jboss.seam.Component.forName(Component.java:1945)
    at org.jboss.seam.Component.getInstance(Component.java:2005)

推荐答案

有一种方法有点脏,很多开发人员永远不会使用这种 hack 但它会解决您的问题:

There is one way that is a little dirty and there are many developers that would not use such a hack ever but it will solve your problem:

import org.jboss.seam.contexts.Lifecycle;

@Service
public class MyService extends DefaultTimedService implements TimedObject, DefaultServiceInterface {
    @Timeout
    public void ejbTimeout(Timer timer) {
        Lifecycle.beginCall();

        MyInterface loader = (MyInterface) Component.getInstance(MyInterface.SEAM_NAME, true);
        // will not throw no context!
        // also the Component.getInstance(MyInterface.SEAM_NAME, true,true); call
        // is another way you could inject that component. 

        Lifecycle.endCall();
    }
}

我在一个项目中使用了它,但我找不到其他任何有效的方法.如果有人有其他解决方案,我很期待在这里看到它:).

I have used it in one project where I couldn't find anything else that worked. If anybody has another solution I am looking forward to seeing it here :).

这篇关于是否可以在 JBoss 定时服务中使用 Seam?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆