Java EE Annotations

JSR 250 (Common Annotations)

  • Since Java EE 5 (May 11, 2006) & Java SE 6
  • All non-Java EE JSR 250 annotations were added to the Java SE with version 6 (Generated, PostConstruct, PreDestroy, Resource, Resources).
  • Yellow ones are security-related annotations.
  • javax.annotation package
Marks sources that have been generated
Declares a reference to a resource, e.g. a database
Container for multiple Resource annotations
Is used on methods that need to get executed after dependency injection is done to perform any initialization.
Is used on methods that are called before the instance is removed from the container
Is used to indicate in what order the classes should be used. For, e.g., the Interceptors specification defines the use of priorities on interceptors to control the order in which interceptors are called.
Defines the role of the application during execution in a Java EE container
Specifies the security roles permitted to access method(s) in an application.
Specifies that all security roles are permitted to access the annotated method, or all methods in the annotated class.
Specifies that no security roles are allowed to invoke the specified method(s).
Used to specify the security roles by the application.
Is used to define a container DataSource and be registered with JNDI. The DataSource may be configured by setting the annotation elements for commonly used DataSource properties.
Is used to declare a Managed Bean which are container managed objects that support a small set of basic services such as resource injection, lifecycle callbacks and interceptors.

JSR 330 (Dependency Injection for Java)

Declares a reference to a dependency
Used to give meaningful names to injections
Used to identify qualifier annotations
Used to identify scope annotations
Identifies a type that the injector only instantiates once
Implemented by an injector and simply provides lazy or optional retrieval of an instance.

Contexts and Dependency Injection

JSR 299 (CDI 1.0: Java Contexts and Dependency Injection - EE6)
JSR 346 (CDI 1.1: Java Contexts and Dependency Injection - EE7)
JSR 365 (CDI 2.0: Java Contexts and Dependency Injection - EE8)
  • JSR-299 is layered on top of JSR-330.
  • In Java EE 6, you can just use JSR-330 for basic stuff, and enhance it on demand with JSR-299. There is almost no overlap in the practice. You can even mix JSR-299 / JSR-330 with EJB 3.1
Associates with the built-in application context.
The application context is shared between all servlet requests, web service invocations, EJB remote method invocations, EJB asynchronous method invocations, EJB timeouts and message deliveries to message-driven beans that execute within the same application.
Associates with the built-in session context.
The session context is shared between all servlet requests that occur in the same HTTP session.
Associates with the built-in conversation context.
Associates with the built-in request context.
When a bean is declared to have scope @Dependent, no injected instance of the bean is ever shared between multiple injection points.
The New qualifier was deprecated in CDI 1.1. CDI applications are encouraged to inject Dependent scoped beans instead.
Specifies that a bean is an alternative. May be applied to a bean class, producer method or field or stereotype.
The @Any qualifier allows an injection point to refer to all beans or all events of a certain bean type.
Identifies a producer method or field. May be applied to a method or field of a bean class.
Identifies the disposed parameter of a disposer method. May be applied to a parameter of a method of a bean class.



Java EE Technology Stack

Dependency Injection In Java and CDI

Proxy Server