简体   繁体   English

从连接工厂创建连接时发生NullPointerException

[英]NullPointerException when creating connection from connection factory

I am trying to create a connection using connectionFactory.createConnection() method but it returns a null. 我正在尝试使用connectionFactory.createConnection()方法创建连接,但它返回null。

Below is my code : 下面是我的代码:

     @Stateless

     public class test

    {
 @Resource(mappedName = "java:comp/DefaultJMSConnectionFactory")     
 private static ConnectionFactory connectionFactory;  
@Resource(mappedName = "jdbc/JurassicParkCon")   
private static Queue queue; 

public static void main(String args[])
{
     Connection connection = null;      
     Session session = null;       
     MessageProducer messageProducer = null;  
     TextMessage message = null;       
     final int NUM_MSGS = 3; 

   try {  
       connection = connectionFactory.createConnection();
       }
       catch(Exception e){System.out.println("It is:"+e.getMessage());}

In the above code am only trying to create a connection but it returns NullPointerException . 在上面的代码中,我只是尝试创建一个连接,但是它返回NullPointerException I have added a JMS resource through the admin console in GlassFish (name is jdbc/JurassicParkCon ). 我已经通过GlassFish中的管理控制台添加了JMS资源(名称为jdbc/JurassicParkCon )。

Recently only I started working with EJB's so I am not very familiar with errors. 最近,只有我开始使用EJB,所以我对错误不是很熟悉。 I have added the @Stateless annotation because there was a similar problem which was posted on StackOverflow and for that user adding the annotation worked but not for me. 我添加了@Stateless批注,因为在StackOverflow上发布了一个类似的问题,对于该用户而言,添加批注有效但对我而言不行。

What might be the problem here ? 这可能是什么问题?

Thank you for your time. 感谢您的时间。

It won't work as a standalone application. 它不能作为独立的应用程序使用。 You need to run it in a container. 您需要在容器中运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从ActiveMQ连接工厂创建连接时,ActiveMQ在启动时失败 - Activemq is failing at startup while creating connection from activemq connection factory 连接时的JDBC连接NullPointerException - JDBC Connection NullPointerException when connecting 启动连接池时出现 NullPointerException - NullPointerException when initiating the connection pool 创建与ESB的连接(Web逻辑,连接工厂)java - Creating a connection to ESB ( Web Logic, connection factory) java 在MultiTenant Connection Provider中选择DataSource时发生NullPointerException - NullPointerException when selecting DataSource in MultiTenant Connection Provider 通过wsadmin创建mq连接工厂时出现java.lang.ClassNotFoundException - java.lang.ClassNotFoundException when creating a mq connection factory through wsadmin 来自URL的KitKat连接在AsyncTask中获取NullPointerException - KitKat Connection from URL get NullPointerException in AsyncTask SQLite JDBC的Connection.preparedStatement中的NullPointerException - NullPointerException from Connection.preparedStatement for SQLite JDBC NullPointerException关闭jdbc连接 - NullPointerException in closing jdbc connection 虚拟主题在使用 ActiveMQ 5.x 的连接工厂时有效,但不是 Artemis 的连接工厂 - Virtual topics work when using ActiveMQ 5.x's connection factory, but not Artemis' connection factory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM