Can I use Seam in the JBoss service?

I started writing a new JBoss service designed to use some existing seam components. But it seems that I cannot access these components due to non-existent contexts. Is it possible to use them differently than in a typical situation with JSF?

A small 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!
    }
}

This raises the following exception, for example:

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)
+5
source share
3 answers

There is one way that is a little dirty, and there are many developers who would never use such a hack, 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();
    }
}

, , . - , :).

+8

? , , .

...

, , Contexts. , ThreadLocal-. , ...

: .

+1

loader , ? Seam, , , ( ):

@In private MyInterface loader;

loader.

, Seam /, :

@Scope(ScopeType.APPLICATION)

@Scope(ScopeType.STATELESS)

: - /, - .

, MyService MyInterface , .

​​concurrency

.

, @Asynchronous, .

+1

All Articles