為何在JBoss中釋出Message-Driven Bean總出Exception in thread "main" javax.naming.Nam
LogBean.java
import javax.ejb.*;
import javax.jms.*;
public class LogBean implements MessageDrivenBean, MessageListener {
protected MessageDrivenContext ctx;
public void setMessageDrivenContext(MessageDrivenContext ctx) {
this.ctx = ctx;
}
public void ejbCreate() {
System.err.println("ejbCreate()");
}
public void onMessage(Message msg) {
TextMessage tm = (TextMessage) msg;
try {
String text = tm.getText();
System.err.println("Received new message : " + text);
}
catch(JMSException e) {
e.printStackTrace();
}
}
public void ejbRemove() {
System.err.println("ejbRemove()");
}
}
*************************************************************
TestClient.java
import javax.naming.*;
import javax.jms.*;
import java.util.*;
public class TestClient {
public static void main (String[] args) throws Exception {
// Initialize JNDI
Context ctx = new InitialContext(System.getProperties());
// 1: Lookup ConnectionFactory via JNDI
TopicConnectionFactory factory =
(TopicConnectionFactory)
ctx.lookup("TopicConnectionFactory");
// 2: Use ConnectionFactory to create JMS connection
TopicConnection connection =
factory.createTopicConnection();
// 3: Use Connection to create session
TopicSession session = connection.createTopicSession(
false, Session.AUTO_ACKNOWLEDGE);
// 4: Lookup Desintation (topic) via JNDI
Topic topic = (Topic) ctx.lookup("topic/testtopic");
// 5: Create a Message Producer
TopicPublisher publisher = session.createPublisher(topic);
// 6: Create a text message, and publish it
TextMessage msg = session.createTextMessage();
msg.setText("This is a test message.");
publisher.publish(msg);
}
}
**********************************************************************
jboss.xml
<?xml version="1.0"?>
<jboss>
<enterprise-bean>
<message-driven>
<ejb-name>Log</ejb-name>
<destination-jndi-name>topic/testtopic</destination-jndi-name>
<resource-ref>
<res-ref-name>TopicConnectionFactory</res-ref-name>
<res-type>javax.jms.TopicConnectionFactory</res-type>
</resource-ref>
</message-driven>
</enterprise-bean>
</jboss>
**************************************************************
ejb-jar.xml
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<message-driven>
<ejb-name>Log</ejb-name>
<ejb-class>LogBean</ejb-class>
<transaction-type>Container</transaction-type>
<message-driven-destination>
<destination-type>javax.jms.Topic</destination-type>
</message-driven-destination>
</message-driven>
</enterprise-beans>
</ejb-jar>
*****************************************************************
環境資訊jndi.properties
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost
import javax.ejb.*;
import javax.jms.*;
public class LogBean implements MessageDrivenBean, MessageListener {
protected MessageDrivenContext ctx;
public void setMessageDrivenContext(MessageDrivenContext ctx) {
this.ctx = ctx;
}
public void ejbCreate() {
System.err.println("ejbCreate()");
}
public void onMessage(Message msg) {
TextMessage tm = (TextMessage) msg;
try {
String text = tm.getText();
System.err.println("Received new message : " + text);
}
catch(JMSException e) {
e.printStackTrace();
}
}
public void ejbRemove() {
System.err.println("ejbRemove()");
}
}
*************************************************************
TestClient.java
import javax.naming.*;
import javax.jms.*;
import java.util.*;
public class TestClient {
public static void main (String[] args) throws Exception {
// Initialize JNDI
Context ctx = new InitialContext(System.getProperties());
// 1: Lookup ConnectionFactory via JNDI
TopicConnectionFactory factory =
(TopicConnectionFactory)
ctx.lookup("TopicConnectionFactory");
// 2: Use ConnectionFactory to create JMS connection
TopicConnection connection =
factory.createTopicConnection();
// 3: Use Connection to create session
TopicSession session = connection.createTopicSession(
false, Session.AUTO_ACKNOWLEDGE);
// 4: Lookup Desintation (topic) via JNDI
Topic topic = (Topic) ctx.lookup("topic/testtopic");
// 5: Create a Message Producer
TopicPublisher publisher = session.createPublisher(topic);
// 6: Create a text message, and publish it
TextMessage msg = session.createTextMessage();
msg.setText("This is a test message.");
publisher.publish(msg);
}
}
**********************************************************************
jboss.xml
<?xml version="1.0"?>
<jboss>
<enterprise-bean>
<message-driven>
<ejb-name>Log</ejb-name>
<destination-jndi-name>topic/testtopic</destination-jndi-name>
<resource-ref>
<res-ref-name>TopicConnectionFactory</res-ref-name>
<res-type>javax.jms.TopicConnectionFactory</res-type>
</resource-ref>
</message-driven>
</enterprise-bean>
</jboss>
**************************************************************
ejb-jar.xml
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<message-driven>
<ejb-name>Log</ejb-name>
<ejb-class>LogBean</ejb-class>
<transaction-type>Container</transaction-type>
<message-driven-destination>
<destination-type>javax.jms.Topic</destination-type>
</message-driven-destination>
</message-driven>
</enterprise-beans>
</ejb-jar>
*****************************************************************
環境資訊jndi.properties
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost
相關文章
- oracle dbca報Exception in thread mainOracleExceptionthreadAI
- Exception in thread "main" java.lang.UnsupportedClassVersionError:ExceptionthreadAIJavaError
- Exception in thread "main" java.lang.NoClassDefFoundErrorExceptionthreadAIJavaError
- Exception in thread “main” 終極解決方案ExceptionthreadAI
- Exception in thread "main" java.lang.NullPointerException: Cannot invokeExceptionthreadAIJavaNull
- 使用maven向jboss釋出war方法總結Maven
- Java報錯:Exception in thread "main" java.lang.UnsupportedClassVersionErrorJavaExceptionthreadAIError
- Exception in thread "main" java.lang.ClassCastException: $Proxy13ExceptionthreadAIJavaAST
- 在jboss3.2.2中釋出ofbizS3
- myeclipse中傳送郵件出現Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStreamEclipseExceptionthreadAIJavaError
- jmeter報錯“Uncaught exception in thread Thread[AWT-EventQueue-0,6,main]“JMeterExceptionthreadAI
- Exception in thread "main" java.lang.NoClassDefFoundError錯誤資訊(轉帖)ExceptionthreadAIJavaError
- JBoss Data Grid 6釋出
- jboss3.0.3釋出錯誤???S3
- jboss釋出目錄問題?
- Appcrawler 執行報錯 Exception in thread "main" java.lang.NullPointerExceptionAPPExceptionthreadAIJavaNull
- oracle dbca報Exception in thread main 問題解決一例OracleExceptionthreadAI
- Exception in thread "main" org.apache.hadoop.security.AccessControlException: Permission deniedUseExceptionthreadAIApacheHadoop
- Exception in thread “main“ java.lang.NoClassDefFoundError: org/apache/http/conn/socket/LayeredConnecExceptionthreadAIJavaErrorApacheHTTP
- Exception in thread “main“ java.lang.ArrayStoreException解決方案(記錄一下)ExceptionthreadAIJava
- Oracle 11g 安裝RAC時報錯'Exception in thread "main" java.lang'OracleExceptionthreadAIJava
- Exception in thread "main" java.lang.UnsatisfiedLinkError: i386/libawt.soExceptionthreadAIJavaError
- 請教jboss 多應用釋出問題
- 解決:Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.ExceptionthreadAIJavaElasticsearch
- Exception in thread "main" ,設定Oracle9i,10g環境變數ExceptionthreadAIOracle變數
- 【原創】eclipse + JBoss 5 + EJB3開發指南(5):使用配置檔案釋出Session BeanEclipseSessionBean
- jbuilderx+jboss3 釋出war時的問題UIS3
- 如何在國內釋出Flutter PluginFlutterPlugin
- myeclipse執行tomcat報錯Exception in thread "main" java.lang.OutOfMemoryError: PermGen space...EclipseTomcatExceptionthreadAIJavaError
- JDK 9 釋出僅數月,為何在生產環境中卻頻遭嫌棄?JDK
- 如何在微信中釋出動態資訊
- linux jboss伺服器釋出簡單java專案Linux伺服器Java
- jb9和jboss3.x釋出entityBean問題S3Bean
- 如何使用bean:write輸出session中的資訊BeanSession
- 使用JBoss部署實體Bean,資料庫是oracle9i,出現錯誤,求助!!!Bean資料庫Oracle
- jboss webservice 使用wsimport工具出錯WebImport
- 初學者如何在部落格園釋出部落格
- Webpack 5.54.0 釋出,重要更新彙總Web