@WebService(endpointInterface = "login")
public class LoginService{
loginCredentials.login();
}
public class LoginCredentials {
@ManagedProperty(name = "applicationBD", value = "#{applicationBD}")
private IApplication applicationBD; //This class is application scoped
How to access applicationBD in this layer?
//facescontext is null while calling this service from SOAP UI
ServletContext servletContext = (ServletContext)FacesContext.getCurrentInstance().getExternalContext()
.getContext();
servletContext.getAttribute("applicationStartupBD");
}
答案 0 :(得分:0)
我不相信你想做什么是可取的,最好的设计。甚至合法:)。您可以从ServletContext
WebServiceContext
将WebServiceContext
的引用注入您的SIB
@Resource
WebServiceContext ctxt;
从WebServiceContext
,检索MessageContext
(它比以前的上下文更接近webservices的SOAP有效负载处理结构)。从此,您将获得ServletContext
MessageContext msgContext = ctxt.getMessageContext();
ServletContext servletContext = (ServletContext)msgContext.get(MessageContext.SERVLET_CONTEXT);
IApplication app = (IApplication) servletContext.getAttribute("applicationStartupBD"); //You can do whatever you please at this point
这是推荐的方法吗?不,你有依赖关系切换。 webapp应该依赖于web服务,而不是相反。 IMO,webapp更容易改变,是堆栈中的第一层。我建议你坚持两层之间松耦合