There are 3 types of resource injections in JavaEE in the order of usage frequency:
To use resource injected at type-level, you will need to do a traditional JNDI lookup. What we have saved here, compared to pre-JavaEE-5, is there is no need for deployment descriptors.
A servlet example in glassfish:
Type-level injections are inherently verbose, compared to field and setter injections, where a bare @EJB or @Resource is sufficient in some cases. Field and setter injections can use the field type and parameter type to infer the resource type, respectively.
Type-level injections can't. All the necessary attributes must be present.
- Field injection.
- Setter injection.
- Type-level injection.
To use resource injected at type-level, you will need to do a traditional JNDI lookup. What we have saved here, compared to pre-JavaEE-5, is there is no need for deployment descriptors.
A servlet example in glassfish:
Type-level injections are inherently verbose, compared to field and setter injections, where a bare @EJB or @Resource is sufficient in some cases. Field and setter injections can use the field type and parameter type to infer the resource type, respectively.
Type-level injections can't. All the necessary attributes must be present.
- For @Resource, you must specify at least name and type.
- For @EJB, you must have at least beanInterface and name.
No comments :
Post a Comment