The following rules apply to how a deployment descriptor entry may override a Resource annotation:
• The relevant deployment descriptor entry is located based on the JNDI name used with the
annotation (either defaulted or provided explicitly).
...
• The injection target, if specified, must name exactly the annotated field or property method.
<env-entry>
...
<env-entry-value>10</env-entry-value>
<injection-target>
<injection-target-class>n1.notes.ejb.EchoBean</injection-target-class>
<injection-target-name>init</injection-target-name>
</injection-target>
</env-entry>
Restrictions on the overriding of environment entry values depend on the type of environment entry.
Resource Manager Connection Factory References
...
The res-type element contains the Java type of the resource manager connection factory that the enterprise
bean code expects. The res-type element is optional if an injection target is specified for the
resource; in this case, the res-type defaults to the type of the injection target.
Info: echo: 10 Init value from deployment descriptor
Restrictions on the overriding of environment entry values depend on the type of environment entry.
...
It is often convenient to declare a field as an injection target, but to specify a default value in the code, as
illustrated in the following example.
// The maximum number of tax exemptions, configured by the Deployer.
@Resource int maxExemptions = 4; // defaults to 4
To support this case, the container must only inject a value for the environment entry if the application
assembler or deployer has specified a value to override the default value. The env-entry-value
element in the deployment descriptor is optional when an injection target is specified. If the element is
not specified, no value will be injected. In addition, if the element is not specified, the named resource is
not initialized in the naming context, and explicit lookups of the named resource will fail.
Consider Paul's rocket mass heater. |