各位大哥,救救我呀!!很简单,但我搞不定....

03-06-06 mengzhihai

1.simple.java

package debugejb;

import javax.ejb.*;

import java.util.*;

import java.rmi.*;

public interface Sample extends javax.ejb.EJBObject {

public java.lang.String test() throws RemoteException;

}

2.SampleBean.java(我加了一个方法)

package debugejb;

import javax.ejb.*;

public class SampleBean implements SessionBean {

SessionContext sessionContext;

public void ejbCreate() throws CreateException {

/**@todo Complete this method*/

}

public void ejbRemove() {

/**@todo Complete this method*/

}

public void ejbActivate() {

/**@todo Complete this method*/

}

public void ejbPassivate() {

/**@todo Complete this method*/

}

public void setSessionContext(SessionContext sessionContext) {

this.sessionContext = sessionContext;

}

public java.lang.String test() {

/**@todo Complete this method*/

int i=0;

i++;

return "sampleBean.test was called!";

}

}

3.SampleHome.java

package debugejb;

import javax.ejb.*;

import java.util.*;

import java.rmi.*;

public interface SampleHome extends javax.ejb.EJBHome {

public Sample create() throws CreateException, RemoteException;

}

4.SampleTestClient1.java<测试程序>

package debugejb;

import javax.naming.*;

import java.util.Properties;

import javax.rmi.PortableRemoteObject;

public class SampleTestClient1 extends Object {

private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. It must be created by calling one of the Home interface methods first.";

private static final int MAX_OUTPUT_LINE_LENGTH = 100;

private boolean logging = true;

private SampleHome sampleHome = null;

private Sample sample = null;

public SampleTestClient1() {

initialize();

}

public void initialize() {

long startTime = 0;

if (logging) {

log("Initializing bean access.");

startTime = System.currentTimeMillis();

}

try {

Context context = getInitialContext();

Object ref = context.lookup("Sample");

sampleHome = (SampleHome) PortableRemoteObject.narrow(ref, SampleHome.class);

if (logging) {

long endTime = System.currentTimeMillis();

log("Succeeded initializing bean access through Home interface.");

log("Execution time: " + (endTime - startTime) + " ms.");

}

}

catch(Exception e) {

if (logging) {

log("Failed initializing bean access.");

}

e.printStackTrace();

}

}

private Context getInitialContext() throws Exception {

String url = "t3://cannac-007:7001";

String user = null;

String password = null;

Properties properties = null;

try {

properties = new Properties();

properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");

properties.put(Context.PROVIDER_URL, url);

if (user != null) {

properties.put(Context.SECURITY_PRINCIPAL, user);

properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);

}

return new InitialContext(properties);

}

catch(Exception e) {

log("Unable to connect to WebLogic server at " + url);

log("Please make sure that the server is running.");

throw e;

}

}

public Sample create() {

long startTime = 0;

if (logging) {

log("Calling create()");

startTime = System.currentTimeMillis();

}

try {

sample = sampleHome.create();

if (logging) {

long endTime = System.currentTimeMillis();

log("Succeeded: create()");

log("Execution time: " + (endTime - startTime) + " ms.");

}

}

catch(Exception e) {

if (logging) {

log("Failed: create()");

}

e.printStackTrace();

}

if (logging) {

log("Return value from create(): " + sample + ".");

}

return sample;

}

public String test() {

String returnvalue = "";

if (sample == null) {

System.out.println("Error in test(): " + ERROR_NULL_REMOTE);

return returnvalue;

}

long startTime = 0;

if (logging) {

log("Calling test()");

startTime = System.currentTimeMillis();

}

try {

returnvalue = sample.test();

if (logging) {

long endTime = System.currentTimeMillis();

log("Succeeded: test()");

log("Execution time: " + (endTime - startTime) + " ms.");

}

}

catch(Exception e) {

if (logging) {

log("Failed: test()");

}

e.printStackTrace();

}

if (logging) {

log("Return value from test(): " + returnvalue + ".");

}

return returnvalue;

}

private void log(String message) {

if (message == null) {

System.out.println("-- null");

return ;

}

if (message.length() > MAX_OUTPUT_LINE_LENGTH) {

System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ...");

}

else {

System.out.println("-- " + message);

}

}

//Main method

public static void main(String[] args) {

SampleTestClient1 client = new SampleTestClient1();

client.create();

String s=client.test();

System.out.println("The return value from EJB is "+s);

}

}

a.编译部署EJB成功<c:\bea\user_projects\mydomain\myserver\upload下>

b.然后在SampleBean.java中的自定义方法<test>的第二行设置了断点,Debug Project图标,并选择server,启动weblogic,服务器启动起来,错误提示如下:

<2003-5-7 下午02时27分28秒> <Error> <Deployer> <149231> <The slave deployer was unable to set the activation state to true for the application _appsdir_DebugEJB_jar

weblogic.management.ApplicationException: activate failed forDebugEJB

{

Module Name: DebugEJB, Error: Exception activating module: EJBModule(DebugEJB,status=PREPARED)

Unable to deploy EJB: Sample from DebugEJB.jar:

Unable to bind EJB Home Interface to the JNDI name: Sample. The error was:

javax.naming.NameAlreadyBoundException: Failed to bind remote object (ClusterableRemoteRef(192.168.0.31 null)/275[debugejb.SampleHome+javax.ejb.EJBHome+weblogic.ejb20.interfaces.RemoteHome]) to replica aware stub at Sample(ClusterableRemoteRef(192.168.0.31 [192.168.0.31/273])/273[debugejb.SampleHome+javax.ejb.EJBHome+weblogic.ejb20.interfaces.RemoteHome]); remaining name ''

TargetException:

Unable to deploy EJB: Sample from DebugEJB.jar:

Unable to bind EJB Home Interface to the JNDI name: Sample. The error was:

javax.naming.NameAlreadyBoundException: Failed to bind remote object (ClusterableRemoteRef(192.168.0.31 null)/275[debugejb.SampleHome+javax.ejb.EJBHome+weblogic.ejb20.interfaces.RemoteHome]) to replica aware stub at Sample(ClusterableRemoteRef(192.168.0.31 [192.168.0.31/273])/273[debugejb.SampleHome+javax.ejb.EJBHome+weblogic.ejb20.interfaces.RemoteHome]); remaining name ''

}

at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:1093)

at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:1022)

at weblogic.management.deploy.slave.SlaveDeployer.setActivationStateForAllApplications(SlaveDeployer.java:617)

at weblogic.management.deploy.slave.SlaveDeployer.resume(SlaveDeployer.java:376)

at weblogic.management.deploy.DeploymentManagerServerLifeCycleImpl.resume(DeploymentManagerServerLifeCycleImpl.java:235)

at weblogic.t3.srvr.ServerLifeCycleList.resume(ServerLifeCycleList.java:65)

at weblogic.t3.srvr.T3Srvr.resume(T3Srvr.java:832)

at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:300)

at weblogic.Server.main(Server.java:32)

>

<2003-5-7 下午02时27分32秒> <Notice> <Management> <141052> <Application Poller started for development server.>

<2003-5-7 下午02时27分56秒> <Notice> <WebLogicServer> <000354> <Thread "SSLListenThread.Default" listening on port 7002>

<2003-5-7 下午02时27分56秒> <Notice> <WebLogicServer> <000354> <Thread "ListenThread.Default" listening on port 7001>

<2003-5-7 下午02时27分56秒> <Notice> <WebLogicServer> <000331> <Started WebLogic Admin Server "myserver" for domain "mydomain" running in Development Mode>

<2003-5-7 下午02时28分02秒> <Notice> <WebLogicServer> <000365> <Server state changed to RUNNING>

<2003-5-7 下午02时28分02秒> <Notice> <WebLogicServer> <000360> <Server started in RUNNING mode>

c.我运行测试程序,错误提示如下:

-- Initializing bean access.

-- Succeeded initializing bean access through Home interface.

-- Execution time: 37975 ms.

-- Calling create()

-- Succeeded: create()

-- Execution time: 811 ms.

-- Return value from create(): debugejb.SampleBean_u71eeu_EOImpl_WLStub@457d21.

-- Calling test()

weblogic.rjvm.PeerGoneException: No message was received for: '240' seconds

at weblogic.rmi.internal.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:109)

at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:263)

at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:230)

-- Failed: test()

at debugejb.SampleBean_u71eeu_EOImpl_WLStub.test(Unknown Source)

at debugejb.SampleTestClient1.test(SampleTestClient1.java:121)

at debugejb.SampleTestClient1.main(SampleTestClient1.java:162)

-- Return value from test(): .

The return value from EJB is

各位大哥麻烦帮看看究竟是那个环节出了问题.....多谢了.....

iceant
2003-06-06 16:25

你的 EJB 的 JNDI 名重名,看看是和什么东西重名了。

重名的东东是不是与你现在的 EJB 的接口不兼容?

mengzhihai
2003-06-09 09:19

重名有那些情况,按理说,应该不会出现这种情况,怎么改呢,请指教.....