删之前重新写一下以防以后遗忘
一、服务器端
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放入部署再生成
二、客户端
查看jndi
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();
}
} }