2012-09-24 14 views
0

我想將EJB(本地)注入Servlet過濾器,並將EAR部署在Weblogic 11g上。使用@EJB注入或每次在Servlet過濾器中執行查找

我的問題是:

難道在@EJB註釋將Weblogic上11克工作,否則將被忽略? OR 我必須做如下查找並提到在web.xml和WebLogic XML文件的引用:

Hashtable env = new Hashtable(); 
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); 
Context ctx = new InitialContext(env); 
ctx.lookup("myejb"); 

感謝

+0

我問這個問題,因爲當我@EJB它拋出NPE在那裏如果我仰望然後正常工作。 – JavaAster

回答

0

我想只supprot如下

更多Rerference :JSF Application that uses managed-bean and ejb

遠程和本地接口

@Remote 
    public interface IPersonEAORemote { 
     public void show(); 
    } 

    @Local 
    public interface IPersonEAOLocal { 
     public void show(); 
    } 

EJB豆

@Stateless(name = "PersonEAO", mappedName = "PersonEAO") 
    public class PersonEAOBean implements IPersonEAORemote, IPersonEAOLocal { 
     /* if you use JPA 
     @PersistenceContext(name = "EJB_DEMO") 
     private EntityManager em; 
     */ 

     public void show() { 
      System.out.println("Good Luck!"); 
     } 
    } 

簡單的客戶端

public class Client { 
     private IPersonEAORemote personEAO; 

     private void init() { 
      try { 
       final Context context = getInitialContext(); 
       personEAO = (IPersonEAORemote)context.lookup("PersonEAO#<your package name>.IPersonEAORemote"); 
      } catch (Exception ex) { 
       ex.printStackTrace(); 
      } 
     } 

     private static Context getInitialContext() throws NamingException { 
      Hashtable env = new Hashtable(); 
      // WebLogic Server 10.x connection details 
      env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); 
      env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7101"); 
      return new InitialContext(env); 
     } 


     public void show() { 
      personEAO.show()); 
     } 

     public static void main(String[] args) { 
      Client client = new Client(); 
      client.init(); 
      client.show(); 
     } 
    } 

ManageBean:比方說,如果你使用JSF,支撐bean就在這裏;

public class JSFBackingBean { 
     @EJB 
     IPersonEAORemote personEAO; 

     public void show() { 
      personEAO.show(); 
     } 
    } 

對於JBoss 5:

Context.INITIAL_CONTEXT_FACTORY ---> org.jnp.interfaces.NamingContextFactory 
    Context.PROVIDER_URL ---->http://localhost:1099 
+0

對不起,我在這裏提供的信息非常少。消費者使用EJB本地接口注入Servlet過濾器,並將EAR部署在Weblogic 11g上。應該在Servlet中注入@EJB註釋在Weblogic 11g中過濾工作還是按照上面在我的文章中提到的方式進行查找? – JavaAster

相關問題