You are writing an EE component that functions as a message producer. The message producer
sends message to a JMS queue. The component environment defines a resource-ref of type
javax.jms.ConnectionFactory with the same jms/ConnectionFactory.
Which will correctly obtain a connection factory for a queue?
A.
Context context = new initialContext();
Connectionfactory confac = (ConnectionFactory) Context.lookup
(�java: comp/env/jms/ConnectionFactory�);
B.
InitialContext Context = new Context () ;
QueueConnectionFactory confac = (QueueConnectionFactory) context.lookup
(�java: comp/env/jms/Myfactory�);
C.
@Resource (�ConnectionFactory�)
private static QueueConnectionFactory confac;
D.
@Resource (loopkup = �jms/QueueConnectionFactory�)
private static ConnectionFactoryconfac;
Explanation:
A connection factory is the object a client uses to create a connection to a
provider. A connection factory encapsulates a set of connection configuration parameters that has
been defined by an administrator. Each connection factory is an instance of
theConnectionFactory, QueueConnectionFactory, or TopicConnectionFactory interface
At the beginning of a JMS client program, you usually inject a connection factory resource into a
ConnectionFactory object. For example, the following code fragment specifies a resource whose
JNDI name is jms/ConnectionFactory and assigns it to a ConnectionFactory object:
@Resource(lookup = “jms/ConnectionFactory”)private static ConnectionFactory connectionFactory;
Reference: The Java EE 6 Tutoria, The JMS API Programming Model
A
D: Cannot be static. So as Marian said, A.
of course it can be static (example here: https://docs.oracle.com/cd/E19798-01/821-1841/bncej/index.html). D is correct.
D
A is correct answer.
ConnectionFactory can be static, but in question D defined jndi name jms/ConnectionFactory and not jms/QueueConnectionFactory as proposes in answer D.
B is correct one