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

1 に答える 1

0

あなたがやりたいことが賢明であり、最高のデザインであるとは確信していません。または合法です:)。ServletContextで始まるチェーンから にアクセスできますWebServiceContext

  1. への参照をWebServiceContextSIB に挿入する

    @Resource
    WebServiceContext ctxt;
    
  2. から、(以前のコンテキストよりも Web サービスの SOAP ペイロード処理構造に近い) をWebServiceContext取得します。MessageContextこれから、あなたは得るでしょう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
    

これは推奨されるアプローチですか?いいえ。依存関係が切り替えられています。Web アプリケーションは Web サービスに依存する必要があり、その逆ではありません。IMO、webapp は変更される可能性が高く、スタックの最初のレイヤーです。両方のレイヤー間の疎結合に固執することをお勧めします

于 2013-04-11T20:24:39.423 に答える