是否可以在JBoss定时服务中使用Seam? [英] Is it possible to use Seam in a JBoss timed service?
问题描述
我已经开始编写一些新的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)
推荐答案
有一种方法有点脏,有很多开发人员不会使用这样的黑客,但它会解决你的问题:
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屋!