zoukankan      html  css  js  c++  java
  • weblogic的ejb远程调用

         这是一篇对EJB远程调用的简单范例。
         1.环境:win7  + weblogic 12c + myeclipse8.5
         2.目的:实现在myeclispe中对weblogic中EJB的远程的调用。
         3.首先写一个简单的java应用接口程序,并生成jar包,并放入weblogic中。具体实现如下:
               1)第一个写的是接口:
                package com.testClass;
                import javax.ejb.Remote;


                @Remote
                 public interface HelloWorld {
                 public String helloWord(String name);
                 }
                 2)实现类:
               package com.testClass.Impl;
               import javax.ejb.Stateless;
               import com.testClass.HelloWorld;


               @Stateless(mappedName = "HelloWorld")  
               public class HelloWordImpl implements HelloWorld{

    public String helloWord(String name) {
    // TODO Auto-generated method stub
    return "helloWord welcome to ejb!" + "/n" + name;
          }
              }
               这里特别注意接口和实现类类名前的@注释。写好接口和实现类之后在weblogic文件中将wlclient.jar拷贝出来并引入工程中。
              接下来将此工程生成为jar包。这里就不说了 ,不会的百度。然后将这个包部署到weblogic中,weblogic的控制界面在ie中输入http://localhost:7001/console
              选择左边的部署。部署完可以在 环境-》 服务器 - 》jndi树中看到发布的ejb接口。




        然后测试代码:
    package EJB;


    import java.util.Properties;


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


    import com.testClass.HelloWorld;


    public class testEJB {


    private static HelloWorld helloWorld = null;


    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Properties properties = new Properties();
    properties.setProperty("java.naming.factory.initial",
    "weblogic.jndi.WLInitialContextFactory");
    properties.setProperty("java.naming.provider.url",
    "t3://localhost:7001");
    properties.setProperty("java.naming.security.principal", "weblogic");
    properties.setProperty("java.naming.security.credentials",
    "weblogic123");


    Context context;
    try {
    context = new InitialContext(properties);
    helloWorld = (HelloWorld) context
    .lookup("HelloWorld#com.testClass.HelloWorld");
    } catch (NamingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }


    String str = helloWorld.helloWord("as");
    System.out.println(str);


    }


    }









  • 相关阅读:
    简谈单线程多线程的理解
    简谈vuex的理解
    简谈自己对redux的理解
    react-native-1
    react中信息传递的几种方式
    简谈对虚拟Dom的理解
    React-小总结
    移动端解决边框1像素问题
    JavaScript标记上的defer与async的作用与区别
    jQuery.smoove — jQuery和CSS3炫酷滚动页面内容元素动画特效插件
  • 原文地址:https://www.cnblogs.com/riskyer/p/3278044.html
Copyright © 2011-2022 走看看