删在此以前再度写一下戒备将来遗忘

删以前再一次写一下防护以后遗忘

 

一、服务器端

图片 1

 

 

package com.ij34.dao;

import javax.ejb.Remote;

/** 
 * @author Admin
 * @date 创建时间:2017-8-23 下午2:36:21 
 * @version 1.0
 *@type_name Hello
 */
@Remote(value=Hellobean.class)
public interface Hello {

    public String getHello(String name);
}

package com.ij34.dao;
import java.util.Date;

import javax.ejb.Stateless;

/** 
 * @author Admin
 * @date 创建时间:2017-8-23 下午2:36:42 
 * @version 1.0
 *@type_name Hellobean
 */
@Stateless(mappedName="mapHellobean")
public class Hellobean implements Hello{

    @Override
    public String getHello(String name) {
        // TODO Auto-generated method stub
        return name+new Date();
    }

}

导出jar放入部署再生成图片 2

 

 

 

 

二、客户端

 图片 3

 

查看jndi

图片 4

 

 

package com.ij34.bean;

import java.util.Properties;

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

import com.ij34.dao.Hello;

/** 
 * @author Admin
 * @date 创建时间:2017-8-23 下午2:47:47 
 * @version 1.0
 *@type_name Test
 */
public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
           Properties properties=new Properties();
           properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
           properties.setProperty(Context.PROVIDER_URL, "t3://localhost:7001");
           try {
            Context ctx=new InitialContext(properties);
            Hello re=(Hello) ctx.lookup("mapHellobean#com.ij34.dao.Hello");
            System.out.println(re.getHello("习大大,"));
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

 

 

 

三、结果

 

图片 5

 

相关文章