Java Reference
In-Depth Information
Chapter 7. Annotations and CDI
Right up to this moment, we had to use annotations and dependency injections
without trying to understand how they work. This chapter therefore aims to present
and highlight improvements in the relevant APIs. The APIs concerned are:
• Common annotations for the Java Platform 1.2
• Contexts and Dependency Injection 1.1
Common
annotations
for
the
Java
platform
The common annotations for the Java platform 1.2 Specification was developed un-
der JSR 250. This section just gives you an overview of improvements in the API. The
complete document specification (for more information) can be downloaded from ht-
tp://jcp.org/aboutJava/communityprocess/mrel/jsr250/index.html .
The goal of this specification
Annotations are a form of metadata that are generally used to describe, configure, or
mark elements (such as class, method, and attribute) of Java code. In the following
code, we use the @Stateless annotation to configure MySessionBean class as
a stateless session bean, we use the @Deprecated annotation to mark oldMeth-
od() method as obsolete, and finally we set the save() method with the @Trans-
actionAttribute annotation so that it will always use a dedicated transaction.
@Stateless
public class MySessionBean {
@Deprecated
public void oldMethod(){}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
Search WWH ::




Custom Search