我有一个 JEE6 应用程序,带有一个 ejb 和一个 web 模块,在 GlassFish 3.1.1 上运行现在我想通过将它(作为会话 Bean)注入几个托管 Bean 来访问一个 WebService (JAX-WS)。
@Stateless
public class AnyService implements AnyServiceLocal {
@WebServiceRef(wsdlLocation = "META-INF/wsdl/AnyService/Any.wsdl")
private AnyService service;
@Override
public String findLastname(Integer key) {
Any port = service.getAnyPort();
AnyPerson sp = port.findAnynumber(key);
return sp.getLastname();
}
}
当我尝试访问它时:
@ManagedBean
@SessionScoped
public class UserBean {
@EJB
private AnyServiceLocal any;
public void findLastname() {
name = any.findLastname(Integer.valueOf(key));
}
}
我会得到这些例外
WARNUNG: A system exception occurred during an invocation on EJB AnyService method public java.lang.String de.mizui.anytest.ejb.bean.AnyService.findLastname(java.lang.Integer)
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5193)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5091)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4879)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:213)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79)
at $Proxy430.findLastname(Unknown Source)
..blabla..
Caused by: javax.xml.ws.soap.SOAPFaultException: java.lang.NullPointerException
at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:193)
at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:134)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:123)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:144)
at $Proxy431.findEmployeenumber(Unknown Source)
at de.mizui.anytest.ejb.bean.AnyService.findLastname(AnyService.java:25)
..blabla..
Caused by: javax.xml.ws.WebServiceException: java.lang.NullPointerException
at com.sun.enterprise.security.jmac.provider.config.PipeHelper.makeFaultResponse(PipeHelper.java:321)
..blabla..
Caused by: java.lang.NullPointerException
at com.sun.xml.ws.tx.coordinator.CoordinationManager.lookupOrCreateCoordinator(CoordinationManager.java:175)
(somewhat shortened..)
但是当我直接从 UserBean 中访问 WS 时,它就可以工作了。期待您的想法 :)
*耶,我的第一篇文章^^