Question 1
Topic: Understand Java EE Architecture
Skill tested: Selects Java EE component scopes and injection mechanisms for web and business tiers.
A Java EE 7 application has a JSF web tier and a service layer packaged in an EAR. Several request-handling components need a shared service object that can participate in container-managed transactions, while request-specific presentation state must not leak between users. The team wants type-safe injection rather than looking up the service by a string name, and it wants the container to manage the service instance lifecycle. Which design best meets these requirements?
A stateless session bean is a container-managed business component with EJB services, including container-managed transactions, and can be injected by type into Java EE components. Request-scoped CDI beans provide isolated state for each request. An application-scoped CDI bean does not by itself provide the EJB transaction semantics requested, and storing per-user state there risks sharing it across users. A servlet is a web component, not an appropriate business-service substitute, while a stateful bean instance is not safely shared through a static field.