mymessage()你定义在Home里干什么?
在Home定义一个方法后要在bean里写上相对应的方法,通常是在前面加上Ejb的两个方法。就如Create方法一样。但从你的错误中发现你并没有这样做。而且,我认为你就是这样做了,也是违背EJB规范的。

解决方案 »

  1.   

    "EJB.ejbgrpx": ERROR: Error from ejbc: Exception: 'java.lang.Error: No production 'business_method' in template.' while trying to invoke: home_methods at line 284
    "EJB.ejbgrpx": ERROR: ejbc found errorsProgram Soruce:Test.java
    //////////////////////////////////
    package ejb;
    import java.rmi.*;
    import javax.ejb.*;
    public interface Test extends EJBObject {
      public String getId() throws RemoteException;
      public String getCode() throws RemoteException;
      public void setCode(String code) throws RemoteException;
      public String getName() throws RemoteException;
      public void setName(String name) throws RemoteException;
    }TestBean.java
    //////////////////////////////////
    package ejb;
    import java.rmi.*;
    import javax.ejb.*;
    public class TestBean implements EntityBean {
      EntityContext entityContext;
      public String id;
      public String code;
      public String name;
      public String ejbCreate(String id, String code, String name) throws CreateException {
        this.id = id;
        this.code = code;
        this.name = name;
        return null;
      }
      public String ejbCreate(String id) throws CreateException {
        return ejbCreate(id, null, null);
      }
      public void ejbPostCreate(String id, String code, String name) throws CreateException {
      }
      public void ejbPostCreate(String id) throws CreateException {
        ejbPostCreate(id, null, null);
      }
      public void ejbLoad() {
      }
      public void ejbStore() {
      }
      public void ejbRemove() throws RemoveException {
      }
      public void ejbActivate() {
      }
      public void ejbPassivate() {
      }
      public void setEntityContext(EntityContext entityContext) {
        this.entityContext = entityContext;
      }
      public void unsetEntityContext() {
        entityContext = null;
      }
      public String getId() {
        return id;
      }
      public String getCode() {
        return code;
      }
      public void setCode(String code) {
        this.code = code;
      }
      public String getName() {
        return name;
      }
      public void setName(String name) {
        this.name = name;
      }
      public String ejbHomeMymessage(){
        return "Test";
      }
      public void ejbHomePostMymessage(){
      }
    }
    TestHome.java
    //////////////////////////////////
    package ejb;
    import java.rmi.*;
    import javax.ejb.*;
    import java.util.Collection;
    public interface TestHome extends EJBHome {
      public Test create(String id, String code, String name) throws RemoteException, CreateException;
      public Test create(String id) throws RemoteException, CreateException;
      public Test findByPrimaryKey(String primaryKey) throws RemoteException, FinderException;
      public Collection findAll() throws RemoteException, FinderException;
      public String mymessage() throws RemoteException;
    }TestClient.java
    ////////////////////////////////////
    package ejb;
    import javax.naming.*;
    import java.util.Properties;
    import javax.rmi.PortableRemoteObject;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.Enumeration;
    import javax.ejb.*;
    import java.rmi.RemoteException;
    import java.util.*;public class TestTestClient extends Object {
      private static final int MAX_OUTPUT_LINE_LENGTH = 50;
      private TestHome testHome = null;
      public TestTestClient() {
        initialize();
      }
      public void initialize() {
        try {
          Context context = getInitialContext();
          Object ref = context.lookup("TestJNDI");
          testHome = (TestHome) PortableRemoteObject.narrow(ref, TestHome.class);
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      private Context getInitialContext() throws Exception {
        String url = "t3://teddy:7001";
        String user = "admin";
        String password = "12345678";
        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) {
          System.out.println("Unable to connect to WebLogic server at " + url);
          System.out.println("Please make sure that the server is running.");
          throw e;
        }
      }
      public void executeRemoteCallsWithDefaultArguments(Test test) {
        if (test == null) {
          return ;
        }
        try {
          test.getId();
          test.getCode();
          test.setCode("");
          test.getName();
          test.setName("");
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      public TestHome getHome() {
        return testHome;
      }
      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);
        }
      }
      public void executeFindAll() {
        try {
          executeCollectionFinder(testHome.findAll());
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      public void executeCollectionFinder(Collection all) {
        try {
          Iterator iterator = all.iterator();
          while (iterator.hasNext()) {
            Object object = iterator.next();
            Test test = (Test) PortableRemoteObject.narrow(object, Test.class);
            log(test.toString());
          }
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      public void executeEnumerationFinder(Enumeration all) {
        try {
          while (all.hasMoreElements()) {
            Object object = all.nextElement();
            Test test = (Test) PortableRemoteObject.narrow(object, Test.class);
            log(test.toString());
          }
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }  public static void main(String[] args) {
        try{
          TestTestClient client = new TestTestClient();
          TestHome home = client.getHome();
          Collection result = home.findAll();
          Test test=home.findByPrimaryKey("1");
          System.out.println(home.mymessage());
          System.out.println(test.getId());
          System.out.println(test.getCode());
          System.out.println(test.getName());
        }
        catch(RemoteException ex){
          ex.printStackTrace();
        }
        catch(FinderException ex){
          ex.printStackTrace();
        }
      }
    }
      

  2.   

    去掉:public void ejbHomePostMymessage()看看。在发布时你看看控制台,是不是出现了警告:home里最好只有create和find