在WebService之外使用WebServiceContext [英] Use WebServiceContext outside WebService
本文介绍了在WebService之外使用WebServiceContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Web服务中,我有:
In my Web service, I have:
@WebService(serviceName = "myservice")
public class ServiceName{
@Resource
private WebServiceContext context;
在无状态类中,我想使用相同的操作:
In a stateless class I want to use the same operation:
@Stateless
public class MakeHappen{
@Resource
private WebServiceContext context;
但是我收到一个EJB异常。如何在Web服务之外注入此资源?
But I receive an EJB exception. How can I inject this resource, outside webservice?
推荐答案
我有任何地方注入它 ,这是怎么回事我解决了这个问题:
I had the same problem and this is how I solved it:
WebServiceContext wscontext = null;
try {
Context ctx = new InitialContext();
wscontext = (WebServiceContext) ctx.lookup("java:comp/WebServiceContext");
} catch (NamingException e) {
}
这篇关于在WebService之外使用WebServiceContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文