2013-10-29 44 views
0

該主要調用的是同一項目中的會話bean,以便將消息發送到單獨項目中的消息驅動bean。在運行客戶端時創建ejb對象的異常Main.java

其他項目已完全部署並正常運行。

對於該項目,可以部署會話bean ejb。問題是,當我嘗試運行我的客戶端主代碼時,netbeans可以部署代碼,但在運行時給我(警告:創建ejb對象的異常:[SSSbean])。我只是不明白爲什麼ejb對象不能創建。有任何想法嗎?

會話Bean低於:

public class SSSbean implements SSSbeanRemote { 

@Resource(name = "jms/Topic") 
private static Topic topic; 
@Resource(name = "jms/TopicConnectionFactory") 
private static ConnectionFactory topicFactory; 

public SSSbean() {} 

@Override 
public void createMessage(String messageData) throws JMSException { 
    Connection topicConnection = null; 
    Session session = null; 
    MessageProducer producer = null; 

    topicConnection = topicFactory.createConnection(); 
    session = topicConnection.createSession(true,0); 
    topicConnection.start(); 
    producer = session.createProducer(topic); 

    TextMessage tm = session.createTextMessage(); 
    tm.setText(messageData); 
    producer.send(tm); 
} 

@Override 
@Remove 
public void remove() { 
    System.out.println("SSSBean:remove()"); 
} 

} 

主要是如下:

public class Main { 
    @EJB 
    private static SSSbeanRemote ss; 

    public static void main(String[] args) { 
     // TODO code application logic here 
     Main client = new Main(); 
     client.bX(); 
     ss.remove(); 
    } 

    private void bX() { 
     System.out.println("Main: Client started... "); 

     Scanner sc = new Scanner(System.in); 

     while (true) { 
      System.out.println("Enter Suggestion: "); 
      String suggestion = sc.nextLine(); 
      try{ 
       ss.createMessage(suggestion); 
       continue; 
      } catch (JMSException j) { 
       System.out.println("Error: "+ j.toString()); 
      } 
     } 
    } 
} 

回答

0

您正在嘗試未由容器管理的代碼中注入的EJB。

當您執行您的客戶端代碼時,main()方法會忽略@EJB註釋。唯一知道@EJB的含義和如何注入Bean的是Container。嘗試執行Aplication Client Container中的客戶端代碼