nerdexam
Oracle

1Z0-900 · Question #41

How can you inject a target web service into an EJB?

The correct answer is A. Define service as an injectable resource by using the <resource-ref> declaration.. Option A is correct because the <resource-ref> declaration in the deployment descriptor (web.xml or ejb-jar.xml) is the standard Java EE mechanism for defining a web service client as an injectable resource, making it available to the EJB container via JNDI lookup or @Resource in

Implement Business Logic by Using EJBs

Question

How can you inject a target web service into an EJB?

Options

  • ADefine service as an injectable resource by using the <resource-ref> declaration.
  • BUse a HandlerChain.
  • CUse a java.xml.ws.WebServiceRef annotation.
  • DUse a java.xml.ws.WebServiceContext annotation.

How the community answered

(14 responses)
  • A
    71% (10)
  • B
    14% (2)
  • C
    7% (1)
  • D
    7% (1)

Explanation

Option A is correct because the <resource-ref> declaration in the deployment descriptor (web.xml or ejb-jar.xml) is the standard Java EE mechanism for defining a web service client as an injectable resource, making it available to the EJB container via JNDI lookup or @Resource injection.

Option B is wrong - a HandlerChain is used to attach SOAP message handlers (for pre/post-processing of web service calls), not to inject a service reference into a component. Option C is a near-miss but uses the incorrect package java.xml.ws; the real injection annotation lives in javax.xml.ws.WebServiceRef - and notably, @WebServiceRef injects a web service client, but the question targets the declarative deployment-descriptor approach. Option D is wrong because @WebServiceContext gives a service implementor access to its runtime context (e.g., MessageContext), not a mechanism for injecting an external service into an EJB.

Memory tip: Think of <resource-ref> as the "label on the shelf" - it tells the container to stock the resource so the EJB can grab it. WebServiceContext = inside the service; HandlerChain = intercepting messages; resource-ref = wiring in an external service.

Topics

#EJB injection#resource-ref#web service injection#JAX-WS

Community Discussion

No community discussion yet for this question.

Full 1Z0-900 Practice