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);


    }


    }









  • 相关阅读:
    vagrant The specified host network collides with a non-hostonly network!
    git ignore 添加忽略文件不生效解决办法
    vagrant up报错 Warning: Authentication failure. Retrying...解决方案
    如何在同一主机中添加多个homestead并行开发
    laravel5.5 excel扩展包的安装和使用
    半分钟学会使用markdown基本语法
    php 二维数组按照指定字段进行排序
    git初始化项目 以及 git常用操作
    laravel5.5的任务调度(定时任务)详解(demo)
    linux mongodb 及php-mongo扩展安装
  • 原文地址:https://www.cnblogs.com/riskyer/p/3278044.html
Copyright © 2011-2022 走看看