16.2.2 Annotations for Environment Entries
A field or method of a bean class may be annotated to request that an entry from the bean s environment
be injected. Any of the types of resources or other environment entries described in this chapter may
be injected. Injection may also be requested using entries in the deployment descriptor corresponding to
each of these resource types.
A.A field of the bean class may be the target of injection. The field must not be final. By default, the name of the field is combined with the name of the class in which the annotation is used and is used directly as the name in the bean’s naming context.
B.Environment entries may also be injected into the bean through bean methods that follow the naming conventions for JavaBeans properties. The annotation is applied to the setmethod for the property, which is the method that is called to inject the environment entry. The JavaBeans property name (not the method name) is used as the default JNDI name. For example, a method named setMyDatabasein the same MySessionBeanclass would correspond to the JNDI name java:comp/env/com.example.MySessionBean/myDatabase
OCPJP 6.0 93%
OCPJWCD 5.0 98%
Statement:A field of the bean class may be the target of injection
Understanding: Does it mean "using Bean Field as a resource ,creating a environmental entry for it and then using it in other fields and methods of other classes".
Understanding:However,the next line "java:comp/env/com.example.MySessionBean/myDatabase" looks like using the method name as resource creating a environmental entry for it and then using it in other fields or methods of other classes.
Each resource may only be injected into a single field or method of the bean. Requesting injection of the java:comp/env/com.example.MySessionBean/myDatabaseresource into both the setMyDatabasemethod and the myDatabaseinstance variable is an error. Note, however, that either the field or the method could request injection of a resource of a different (non-default) name.
OCPJP 6.0 93%
OCPJWCD 5.0 98%
Question 1:Why is the JNDI name(java:comp/env/com.acme.example.MySession-Bean/myDatabase) created for the field of Bean class/bean methods to which a resource is injected instead of creating JNDI name for the actual resource ?
If field or the method request injection of a resource of a different (non-default) name,Then How can one differentiate b/w the JNDI name for method and field (In below 2 statements,it seems JNDI name doesn't changes with change in a different resource injection)?
I guess that they mean here that if you use a non-default name you can still only inject it in either a field or a setter but not in both
OCPJP 6.0 93%
OCPJWCD 5.0 98%
OCPJP 6.0 93%
OCPJWCD 5.0 98%
why is the following JNDI name created for the field of Bean class/bean methods to which a resource is injected instead of creating JNDI name for the actual resource
Frits,Can you please provide a example showing the same.
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|