| Author |
Is it possible to initialize a no-interface Stateful bean through annotation?
|
Rob Micah
Ranch Hand
Joined: Aug 30, 2011
Posts: 89
|
|
|
If I have a method defined in my Stateful bean I want to be an "initializer" can I use that somehow when creating a reference to it in a client through the @EJB annotation?
|
 |
Piotr Nowicki
Ranch Hand
Joined: Jul 13, 2010
Posts: 610
|
|
I'm not sure what you want to do :-)
Do you want just to have an initializer method for your SFSB? If so, can you use the @PostConstruct annotation on your method?
Cheers!
|
OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
|
 |
Rob Micah
Ranch Hand
Joined: Aug 30, 2011
Posts: 89
|
|
I want to have a method in the bean like
So that when the bean is instantiated it's provided a String to work with. And restrict it to only being initialized that way. I just don't know how to make that work with something like this:
|
 |
Piotr Nowicki
Ranch Hand
Joined: Jul 13, 2010
Posts: 610
|
|
|
And where from would you like this String argument come? From the client?
|
 |
Rob Micah
Ranch Hand
Joined: Aug 30, 2011
Posts: 89
|
|
|
Yes it will come from the client.
|
 |
Piotr Nowicki
Ranch Hand
Joined: Jul 13, 2010
Posts: 610
|
|
As far as I know you can only initialize an EJB using @PostConstruct method which takes no parameters. It's invoked by the container and it's the only hook to use between class instantiatation and giving it's EJB nature.
I think you'll need to go with specific business method that you'll invoke in order to store the data as a part of the conversational state. If the particular data / parameter is required to be set for further processing, you can check this and throw i.e. some IllegalStateException or ApplicationException.
|
 |
Rob Micah
Ranch Hand
Joined: Aug 30, 2011
Posts: 89
|
|
|
I thought there was a way to do this, without using annotation/dependency injection, by creating an ejbCreate() method in the local interface that had parameters and then when looking up through JNDI you pass those parameters to the create() method. Am I mistaken?
|
 |
Piotr Nowicki
Ranch Hand
Joined: Jul 13, 2010
Posts: 610
|
|
|
Then sorry, I'm not aware of how the EJB 2.x were used... I worked only with 3.x.
|
 |
Anastasia Klimchuk
Greenhorn
Joined: Sep 21, 2011
Posts: 10
|
|
Actually, there are several annotations that deal with Stateful beans initialization,
But this seems like returning to old style. As I understand, these annotations were mainly added to provide backward compartibility with EJB 2.1.
and... wow the same advice is here http://www.coderanch.com/t/318886/EJB-JEE/java/EJB-Passing-intialization-parameters-absence
|
 |
 |
|
|
subject: Is it possible to initialize a no-interface Stateful bean through annotation?
|
|
|