jms中not bound问题解决方法

                 jms中将服务器端部署在jboss服务器中启动时会遇到这样一个问题,就是提示myqueue notbound,这也是我们部署类似jms的实例过程中很常见的一个问题

         实例代码如下:

客户端代码如下:
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.TextMessage;
import javax.naming.InitialContext;

public class MyQueueMDBBeanClient {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		InitialContext context = new InitialContext();
        //获取QueueConnectionFactory对象		
		QueueConnectionFactory factory =(QueueConnectionFactory)context.lookup("ConnectionFactory");
		
		//创建QueueConnection 
		QueueConnection connection = factory.createQueueConnection();
		
		//创建Queuesession对象
		QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
		
		//获取Destination对象
		Queue queue =  (Queue)context.lookup("queue/myqueue");
		
		//创建文本消息
		TextMessage msg = session.createTextMessage("世界,您好");
		
		//创建发送者
		QueueSender sender = session.createSender(queue);
		
		//发送消息
		sender.send(msg);
		
		//关闭会话
		session.close();
		connection.close();
		System.out.println("消息已发送");
	}

}




服务器端代码如下:
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import javax.ejb.ActivationConfigProperty;
@MessageDriven( 
	activationConfig = {
	@ActivationConfigProperty(propertyName="destinationType",propertyValue="javax.jms.Queue"),
	@ActivationConfigProperty(propertyName="destination",propertyValue="queue/myqueue")
	}
)

public class MyQueueMDBBean implements MessageListener {

	public void onMessage(Message msg) {
		 try{
			 TextMessage textMessage = (TextMessage)msg;
			 System.out.println("MyQueueMDBBean被调用了【" +textMessage.getText() +"】");
		 }catch(JMSException e){
			 e.printStackTrace();
		 }		
	}

}


       这个问题主要是jboss升级版本之后不再认可这种写法了,所以我们需要在JBoss根目录\server\default\deploy下的mail-service.xml文件中加入如下内容:

 

<mbeancode="org.jboss.mq.server.jmx.Queue"name="jboss.org.destination:server=Queue,name=myqueue" >

<attributename="JNDIName" >queue/myqueue</attribute>

<dependsoptional-attribute-name = "DestinationManager" >jboss.mq:service=DestinationManager </depends>

< /mbean>


 

      以上解决方案并不是唯一的解决方案,所以不要认为是必须要有这个xml文件,网上还有人用第二种解决方案,就是:在annotation里把destination "jms/" 改成 "queue/.根本原因是在实例中jms destination 的JNDI写的是"jms/xxxx",jboss已经不识别这种写法了,我们改为queuejboss就自动识别了,就省得去改xml文件了.不过我没有实验成功,这个有待继续考证一下.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
当出现"Invalid bound statement (not found)"错误时,可能由以下几种原因导致: 1. mapper方法名和mapper.xml的id不匹配。请确保mapper接口方法名与mapper.xml文件的id名保持一致。检查方法名的拼写和大小写是否正确。 2. 在搭建项目时使用了MyBatis Plus,但是没有正确配置mapper接口和mapper.xml的对应关系。在使用MyBatis Plus时,需要在mapper接口上添加`@Mapper`注解,并且在application.yml或application.properties配置文件正确指定mapper.xml的位置。如果没有正确配置对应关系,会导致"Invalid bound statement (not found)"错误。请检查相关配置是否正确。 3. 可能是IDE或编辑器的插件问题。有些IDE或编辑器提供了MyBatis相关的插件,这些插件可以帮助我们更方便地编写mapper接口和mapper.xml。但是如果插件配置不正确或版本不兼容,可能会导致"Invalid bound statement (not found)"错误。请检查插件的配置和版本是否正确,并尝试重新安装或更新插件。 综上所述,要解决"Invalid bound statement (not found)"错误,需要检查mapper方法名和mapper.xml的id是否匹配,确保MyBatis Plus的配置正确,以及检查IDE或编辑器的插件配置和版本。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Invalid bound statement (not found)的原因以及解决方法](https://blog.csdn.net/axbhealj/article/details/130331164)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [mybatisplus报Invalid bound statement (not found)错误的解决方法](https://download.csdn.net/download/weixin_38625442/12821082)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值