首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从bean风格的bean服务调用messge bean

无法从bean风格的bean服务调用messge bean
EN

Stack Overflow用户
提问于 2011-04-23 15:45:01
回答 3查看 938关注 0票数 1

我正在尝试创建Restful Webservice作为消息驱动Bean的客户端,但是当我调用restful方法时,它会给我以下错误

代码语言:javascript
复制
Connection connection =  connectionFactory.createConnection();

SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NullPointerException
        at com.quant.ws.GetConnection.startThread(GetConnection.java:99)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 

下面是代码:

代码语言:javascript
复制
// Inside class declaration
@Resource(mappedName = "jms/testFactory")
private static ConnectionFactory connectionFactory;

@Resource(mappedName = "jms/test")
private static Queue queue;

Web服务方法

代码语言:javascript
复制
@GET
@Path("startThread")
@Produces("application/xml")
public String startThread()
{

    try{
    Connection connection =  connectionFactory.createConnection(); // its line number 99
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer( queue);
    Message message = session.createTextMessage();
    message.setStringProperty("name", "start");
    producer.send(message);
    }catch(JMSException e){
        System.out.println(e);
    }
   return "<data>START</data>";
}

我是否需要在sun-web.xml或web.xml中指定任何内容?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-04-24 13:06:16

我已经通过替换下面的代码解决了这个问题

代码语言:javascript
复制
  try{
       InitialContext ctx = new InitialContext();
      queue = (Queue) ctx.lookup("jms/test");
      QueueConnectionFactory factory =
      (QueueConnectionFactory) ctx.lookup("jms/testFactory");
      Connection connection = factory.createConnection();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer( queue);

        Message message = session.createTextMessage();
        message.setStringProperty("name", "start");
        producer.send(message);

     }
     catch(NamingException e){
         System.out.println(e);
     }
     catch(JMSException e){
     System.out.println(e);
     }
票数 0
EN

Stack Overflow用户

发布于 2011-04-23 16:27:37

我想这取决于你的应用服务器设置。你在上面的某个地方注射了connectionFactory吗?还是做了上下文查询?

票数 1
EN

Stack Overflow用户

发布于 2011-04-23 17:08:15

connectionFactory为空。它需要以某种方式进行初始化。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5762972

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档