[jboss-user] [EJB3] - 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?
Adheep M
do-not-reply at jboss.com
Fri Jun 22 08:17:44 EDT 2012
Adheep M [https://community.jboss.org/people/adheep] created the discussion
"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?"
To view the discussion, visit: https://community.jboss.org/message/743664#743664
--------------------------------------------------------------
> Viggo Navarsete wrote:
>
> No, the "Testing Value" will not be there on the second request! But, it shouldn't be too difficult for you to actually test it, or? But I would assume that if you set a value on the simpleSingletonBean on the first request, then it would still be there on the second request!
I did try an example and below are the codes
package com.sample.rest.service;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.test.ejb.PrimaryStatelessBean;
import com.test.ejb.SampleSingletonBean;
@Stateless
@Path("/services")
public class PrimaryStatelessBean{
@EJB
PrimaryStatelessBean primaryStatelessBean;
@EJB
SampleSingletonBean sampleSingletonBean;
@GET
@Path("/getValue")
@Produces("text/xml")
public String getValue(){
//To get initial value
System.out.println("Before Setting Value::" + primaryStatelessBean.getMessage());
//set value for the Bean
primaryStatelessBean.setMessage("Hi Buddy Cool!!");
//After setting value
System.out.println("After Setting Value::" + primaryStatelessBean.getMessage());
return "<MESSAGE>"+primaryStatelessBean.getMessage()+"</MESSAGE><REQUEST_COUNT>"+ sampleSingletonBean.getCount() +"</REQUEST_COUNT>";
}
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/743664#743664]
Start a new discussion in EJB3 at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120622/48439e6b/attachment.html
More information about the jboss-user
mailing list