-
1. Re: PostConstruct and Stateless scoped components
cash1981 Nov 9, 2009 5:55 PM (in response to navansys)In java ee 5 you need to implement an interface for the stateless ejb.
public interface MyStatelessComponentManager { public void init(); public String whatsMyState(); } //Try this public class MyStatelessComponent implements MyStatelessComponentManager {}
@PostConstruct should work just fine.
-
2. Re: PostConstruct and Stateless scoped components
cash1981 Nov 9, 2009 5:58 PM (in response to navansys)Forgot to say that you need to do this after you implement interface.
MyStatelessComponentManager msc = (MyStatelessComponentManager) Component.getInstance( "myStatelessComponent");
It will give you an implementation of your MyStatelessComponentManager which is (MyStatelessComponent)
-
3. Re: PostConstruct and Stateless scoped components
navansys Nov 9, 2009 6:45 PM (in response to navansys)My example is not a stateless session bean. It is a stateless context seam component. According to my Seam in Action book, Stateless context is
a nonstoring context. Forces a component to be instantiated each time the component name is resolved. Equivalent to Spring's prototype scope.
Another example of a stateless context component is org.jboss.seam.persistence.HibernatePersistenceProvider.class, which, being a stateless component, has the same problem: it does not invoke the @PostConstruct method on construction.
-
4. Re: PostConstruct and Stateless scoped components
navansys Nov 10, 2009 10:00 PM (in response to navansys)Found the mistake.
I used this PostConstruct annotation:
import org.jboss.seam.annotations.intercept.PostConstruct;
Seam Component class is looking for:
import javax.annotation.PostConstruct;
As a result the Component class was not picking up my postconstruct method.
I based my stateless component on the Seam PersistenceProvider class (class org.jboss.seam.persistence.PersistenceProvider), which also uses the first PostConstruct annotation for it's init method.
PersistenceProvider therefore has the same error. PersistenceProvider.init() is therefore also not invoked postconstruct. It must be modified to reference javax.annotation.PostConstruct instead.
This is a bug in the current Seam library: 2.2.0.GA.