用weblogic部署ejb2.0,怎么访问本地接口?有谁可以提供一个例子,最好把依赖的jar附上。谢谢

 如题!

ejb2.0 ejb3.0 远程的本地的,调用方法都给你写出来了,你还不知道,连怎么从web组件中调用都写给你了,你脑袋没有毛病吧?

[size=small][code="java"]package com.copote.fygl.sjwh;

import java.util.HashMap;
import java.util.Properties;

import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.copote.cpstmg.ejb.cpstmgEJBFactory;
import com.copote.tframe.biz.BizProcessor;
import com.copote.tframe.biz.Dataset;
import com.copote.tframe.common.Record;

import copote.fygl.CPST_FYGLLocal;
import copote.fygl.CPST_FYGLLocalHome;
import copote.fygl.CPST_FYGLRemote;
import copote.fygl.CPST_FYGLRemoteHome;
/**

  • 仿印制品规格维护
  • @author Administrator 戴忠德 qq:413881261 csdn: jjk_02027 javaeye: 飞火流星
    *
    */
    public class fyzpgg_BZ_main extends BizProcessor {
    // private CPST_FYGLLocal m_ejbFYGLRemote = null;
    private CPST_FYGLRemote m_ejbFYGLRemote = null;

    private void createEjbAsNeeded() throws Exception {
    /* JBoss5.1.0
    * Properties props = new Properties();
    * props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
    * props.setProperty("java.naming.provider.url", "Socket/RMI://localhost:1099");
    * InitialContext ctx = new InitialContext(props);
    *
    * WebLogic8.1.6
    * Properties props = new Properties();
    * props.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
    * props.put(Context.PROVIDER_URL, "t3://10.3.7.44:7001");
    * InitialContext ctx = new InitialContext(props);
    *
    * EJB2.X
    * 调用远程接口
    * CPST_FYGLRemoteHome home = (CPST_FYGLRemoteHome) ctx.lookup("CPST_FYGL");

    • m_ejbFYGLRemote = home.create();
    • 调用本地接口
      • CPST_FYGLLocalHome home = (CPST_FYGLLocalHome) ctx.lookup("CPST_FYGLLocal");
      • m_ejbFYGLLocal = home.create();
      • EJB3.0
      • 调用远程接口
      • m_ejbFYGLRemote = (CPST_FYGLRemote) ctx.lookup("CPST_FYGL#copote.fygl.CPST_FYGLRemote");
      • 调用本地接口
      • m_ejbFYGLLocal = (CPST_FYGLLocal) ctx.lookup("java:comp/env/ejb/CPST_FYGLLocal");
      • EJB2.X调用本地接口可:先通过web.xml在JNDI ENC中注册,再查找当前Web组件的上下文(即:web.xml中定义)
      • EJB3.0调用本地接口需要在web.xml中定义 * */ if (m_ejbFYGLRemote == null) { Properties props = new Properties(); props.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); props.put(Context.PROVIDER_URL, "t3://10.3.15.78:7001"); try { System.out.println("hello 小戴,帅锅!"); InitialContext ctx = new InitialContext(props); // EJB2.X调用远程接口 CPST_FYGLRemoteHome home = (CPST_FYGLRemoteHome) ctx.lookup("CPST_FYGL"); m_ejbFYGLRemote = home.create(); //EJB2.X调用本地接口 // CPST_FYGLLocalHome home = (CPST_FYGLLocalHome) ctx.lookup("CPST_FYGLLocal"); // m_ejbFYGLRemote = home.create(); // EJB2.X调用本地接口,查找当前Web组件的上下文 // CPST_FYGLLocalHome home = (CPST_FYGLLocalHome) ctx.lookup("java:comp/env/ejb/CPST_FYGLLocal"); // m_ejbFYGLRemote = home.create(); }catch (NamingException e){ throw e; // }catch( CreateException e){ // throw e; } } }

    public void doBizProcess() throws Exception {
    m_ejbFYGLRemote.sjwh_Operate_fyzpgg(Index_added, (HashMap) hm_added
    .clone(), Index_deleted, (HashMap) hm_deleted.clone(),
    Index_modified, (HashMap) hm_modified.clone());

        m_ejbFYGLRemote.remove();
    } catch (Exception ex) {
        throw new Exception(ex.getMessage());
    }
    

    }
    }
    [/code][/size]

ejb-jar.xml (ejb2.X)
[code="java"]<!-- ######仿印管理############## -->

仿印管理
CPST_FYGL
copote.fygl.CPST_FYGLRemoteHome
copote.fygl.CPST_FYGLRemote
copote.fygl.CPST_FYGLLocalHome
copote.fygl.CPST_FYGLLocal
copote.fygl.CPST_FYGLBean
Stateless
Container
[/code]

weblogic-ejb-jar.xml (ejb2.X)
[code="java"] <!-- author 戴忠德 ############# begin ##################### -->
<!-- ######仿印管理############## -->

CPST_FYGL
CPST_FYGL
CPST_FYGLLocal
[/code]

web.xml(ejb2.X+ejb3.X)
[code="java"] <!-- 如果引用的是EJB3.0,则需去掉 -->

仿印管理
ejb/CPST_FYGLLocal
Session
copote.fygl.CPST_FYGLLocalHome
copote.fygl.CPST_FYGLLocal
<!-- 如果一个EAR文件中存在多个EJB jar,而这些jar分别含有相同名称的EJB时,
应在EJB名称前加上jar文件名和#号,如:HelloWorld.jar#HelloWorldBean -->
CPST_FYGL
[/code]

那些你都不用管,你只管:
//EJB2.X调用本地接口

71.// CPST_FYGLLocalHome home = (CPST_FYGLLocalHome) ctx.lookup("CPST_FYGLLocal");

不就行了啊!

[code="java"]//EJB2.X调用本地接口

CPST_FYGLLocalHome home = (CPST_FYGLLocalHome) ctx.lookup("CPST_FYGLLocal");

m_ejbFYGLRemote = home.create();

m_ejbFYGLRemote.sjwh_Operate_fyzpgg(。。。); [/code]

这些还不够吗?