我有以下情况:请求范围的JAX-RS服务调用无状态EJB3 bean和EJB3 Bean会从客户端的Web服务的调用连续保持之间的状态。
代码如下:
网络服务
@javax.enterprise.context.RequestScoped
@Path("/actions")
public class CounterFrontEnd {
@EJB
private ICounterService.ILocal counterService;
@GET @Produces("application/text;") @Path("/counter")
public String counter() {
return String.format("%d ", counterService.incCounter());
}
无国籍EJB3豆
@Stateless
@Local (ICounterService.ILocal.class)
@Remote(ICounterService.IRemote.class)
public class CounterService implements ICounterService.ILocal, ICounterService.IRemote {
public int counter = 0;
@Override
public int incCounter() {
return counter++;
}
然后我调用与下面的python脚本的服务:
for i in range(100):
os.system( 'curl http://somewhere:8080/counter-ws/rest/actions/counter' )
出人意料的是,输出为:
1 2 3 4 5 ...