4
我有麻烦让我的连接工厂使用注释资源。 它与JNDI查找效果很好,但它没有注释,我的连接工厂为空。EJB中资源注入的问题
这是我的代码与JNDI查找(作品):
ConnectionFactory factory = (ConnectionFactory)context.lookup("/ConnectionFactory");
这是我的代码与注释:
@Resource(mappedName = "java:/ConnectionFactory")
private ConnectionFactory factory;
我已经用不同的mappedName试图为:/ ConnectionFactory的,JAVA :/ JmsXA,JmsXA等,但仍然nullpointerexception: - /。
如果有人有一个想法...
Thx!
这是我的课:
@Stateless
public class ModuleCommunicationHandler implements IModuleCommunicationHandler
{
/** The connection factory. */
@Resource(mappedName = "java:/ConnectionFactory")
private ConnectionFactory factory;
...........
/**
* {@inheritDoc}
*/
@Override
public void sendMessage(JMSMessage jmsMessage, int deliveryMode, int acknowledgeMode) throws TechnicalException
{
try
{
context = new InitialContext();
factory = (ConnectionFactory)context.lookup("/ConnectionFactory");
// Setting the destination - Topic or Queue
destination = (Destination)context.lookup(jmsMessage.getDestination());
connection = factory.createConnection();
session = connection.createSession(false, acknowledgeMode);
sender = session.createProducer(destination);
connection.start();
// Creating the message
message = session.createTextMessage();
message.setText(jmsMessage.getBodyMessage());
// Sending the message
sender.setDeliveryMode(deliveryMode);
sender.send(message);
.....
这是日志:
15:05:32,609 ERROR [STDERR] com.*.*.*.server.exception.ModuleCommunicationException: java.lang.NullPointerException
15:05:32,609 ERROR [STDERR] at com.*.*.*.server.service.ModuleCommunicationHandler.sendMessage(ModuleCommunicationHandler.java:147)
15:05:32,664 ERROR [STDERR] Caused by: java.lang.NullPointerException
15:05:32,664 ERROR [STDERR] at com.*.*.*.server.service.ModuleCommunicationHandler.sendMessage(ModuleCommunicationHandler.java:108)
当我尝试与我的工厂建立连接时,会引发此错误 –