JBoss Community

Re: How does a @EJB dependency injection work on a Stateless Bean? Will that injected class behave like an instance variable in that stateless session bean?

created by Adheep M in EJB3 - View the full discussion

@Viggo Navarsete: Thanks for your reply.

 

But this brings me an another question, Supose if a method in "PrimaryStatelessBean" is annotated with REST will it work the same way, because we will not create a new instance for the PrimaryStatelessBean if it is invoked as a RESTful webservice.

@Stateless
public class PrimaryStatelessBean {
 
     @EJB
     SecodaryStatelessBean secondaryStatelessBean;
 
     @EJB
     SimpleSingletonBean simpleSingletonBean;
      
          @POST
          @Path("/requestService")
          @Consumes("*/*")
          @Produces("*/*")
     public String processRequest ( ) {
          
          .....
          
 
          secondaryStatelessBean.getValue();   //(After making a first request) When I make another request will i get the same value "Testing Value" here
 
          simpleSingletonBean.getAnotherValue();
 
 
 
 
          secondaryStatelessBean.setValue("Testing Value");   // set values for secondaryStatelessBean in the first request
          ....
 
          
 
 
     }
 
}

On the first request to my to "processRequest" service using REST, if i change the value of a member variable in SecondaryStatelessBean by

 

secondaryStatelessBean.setValue("Testing Value");   // set values for secondaryStatelessBean in the first request

 

and on the next request, will i get the value "Testing Value" here ?

 

secondaryStatelessBean.getValue();   //(After making a first request) When I make another request will i get the same value "Testing Value" here

Reply to this message by going to Community

Start a new discussion in EJB3 at Community