[英]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.