1
@WebService(endpointInterface = "login")
public class LoginService{
 loginCredentials.login();
 }

公共类登录凭据{

@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");
}
4

1 回答 1

0

我不相信你想做的是明智的,最好的设计。甚至是合法的:)。您可以ServletContext从以WebServiceContext

  1. 将引用注入WebServiceContext到您的 SIB

    @Resource
    WebServiceContext ctxt;
    
  2. 从 中WebServiceContext,检索MessageContext(比之前的上下文更接近于 Web 服务的 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 更容易发生变化,并且是堆栈中的第一层。我建议您坚持两层之间的松散耦合

于 2013-04-11T20:24:39.423 回答