Java Annotations Catalog

While there is and can be no complete catalog of Java annotations since anybody can create their own, here are some of the annotations commonly used in the Java Enterprise.

Table 1. Common Annotations
Name API Meaning

@After

JUnit4

Run instance method after each test

@AfterAll

JUnit5

method should be executed after all tests in the current test class.

@AfterClass

JUnit4

Run static method after all tests

@AfterEach

JUnit5

method should be executed after each @Test method in the current test class.

@ApplicationPath

JAX-RS

Root path of REST calls

@ApplicationScoped

CDI/JSF

Object scoped to entire application

@Basic

JPA

Specify column parameters

@Bean

Spring

Marks method as bean provider (advanced topic)

@Before

JUnit4

Run before each test all tests

@BeforeAll

JUnit5

method should be executed before all tests in the current test class.

@BeforeClass

JUnit4

Run static method before all tests

@BeforeEach

JUnit5

method should be executed before each @Test method in the current test class.

@Column

JPA

Override defaults such as column name

@Component

Spring

Makes this object a Bean

@Consumes

JAX-RS

Content-type to accept and to translate object from

@Context

@Controller

SpringMVC

Mark class as web handler

@ConversationScoped

@Convert

@Converter

JSF

Specifies which converter to use

@Dependent

CDI

Object depends on another object

@Deprecated

@Disabled

JUnit5

test class or test method is currently disabled and should not be executed.

@DiscriminatorColumn

JPA

For SINGLE_TABLE: name of type field

@DiscriminatorValue

JPA

For SINGLE_TABLE: value of type field for this subclass

@DisplayName

JUnit5

declare a custom display name for the annotated test class or test method.

@ElementCollection

JPA

@Embeddable/@Embedded

JPA

Embedded object lives in same row of database

@EmbeddedId

JPA

Compount Primary Key is embedded

@End

@Entity

JPA

Object is a JPA Entity

@Enumerated

JPA

Property is a Java Annotation

@FacesConverter

JSF

Object is a JSF converter

@Field

@FormParam

JAX-RS

Name of form submit to retrieve and pass into method

@FunctionalInterface

java.lang

Interface is claimed to be functional (one non-default method)

@GET

JAX-RS

REST method invoked with HTTP GET

@GeneratedValue

JPA

How to generate primary key for new objects

@HeaderParam

JAX-RS

Name of HTTP Header to retrieve and pass into method

@Id

JPA

Property maps to primary key column

@Ignore

@Indexed

@Inheritance

JPA

Type of inheritance strategy to use

@Inject

CDI

Inject object

@JoinColumn

JPA

Name of column used to join tables

@Lob

JPA

Object is a Large (binary) Object

@Local

EJB

EJB is to be accessed locally (in-vm)

@ManagedBean

CDI/JSF

Object is a JSF backing bean

@ManagedProperty

@ManyToMany

JPA

Relationship

@ManyToOne

JPA

Relationship

@MapKey

@Min @Max

BVS

Property must be within range to pass validation

@ModelAttribute

SpringMVC

Command Object parameter to method is in ModelMap

@Mojo

Maven

@Named

CDI

Used to disambiguate CDI injections

@NamedQuery/NamedQueries

JPA

Externalized JPA Query

@Nested

JUnit5

class

JUnit5

nested

non-static test class.

@NotNull

BVS

Element may not be null

@OneToOne

JPA

Specify relationship ordinality

@OrderBy

JPA

Specify sort order on a relationship

@OrderColumn

JPA

@Override

java.lang

Compile-time: ensure method is override not overload

@POST

JAX-RS

REST method invoked with specified HTTP method

@PUT

JAX-RS

REST method invoked with specified HTTP method

@Parameter

@Parameters

Wrapper for multiple @Parameter

@Path

JAX-RS

Path to REST service or method

@PathParam

JAX-RS

Name of parameter from @Path template to pass into method

@Pattern

BVS

Property must match regex pattern to be valid

@PermitAll

EJB

Allow any user to invoke EJB method

@PersistenceContext

JPA

Inject an EntityManager

@PersistenceUnit

JPA

Inject an EntityManagerFactory

@PostActivate

EJB3

Method called after bean is re-activated

@PostConstruct

JA

Called after object has been constructed

@PostParam

JAX-RS

@PreDestroy

JPA

@PrePassivate

EJB3

Method called before bean is passivated

@PrePersist

JPA

Invoke method before persisting new entity

@PreUpdate

JPA

Invoke method before updating existing entity

@Produces

JAX-RS

Content-type to produce and to translate return object into

@Qualifier

CDI

@Query

DSD

Specifies JPA query for interface method

@Remote

EJB

EJB is for remote (JNDI/RMI) access

@Remove

EJB

Method disconnects client from bean and removes state from memory

@Repository

DS-D

DeltaSpike Data: Interface or Abstract Class → DAO

@RequestMapping

SpringMVC

Web Method URL

HTTP Method

etc.

@RequestParam

SpringMVC

Map HTTP request parameter to method parameter

@RequestScoped

CDI/JSF

Bean scoped to HTTP Request

@Resource

JI

Request injection of resource

@Retention

java.lang

Retention policy for annotation

@RolesAllowed

EJB

Specify container-managed security roles allowed to invoke method

@RunWith

JUnit4

Specify alternate test runner

@SandBox

@SecondaryTable

JPA

@SessionScoped

CDI/JSF

Object scoped to HTTP Session

@Singleton

EJB

Instantiate EJB only once

@Size

@Startup

@Stateful

EJB

Object is Stateful Session Bean (SFSB)

@Stateless

EJB

Object is Stateless Session Bean (SFSB)

@SuppressWarnings

java.lang

Basic compiler warning supression

@Table

JPA

Specify table name etc for JPA Entity

@Tag

JUnit5

repeatable annotation declares a tag for the annotated test class or test method.

@Tags

JUnit5

container for one or more @Tag declarations.

@Target

@TargetApi

Android

@Temporal

JPA

Property is a date and/or time field

@Test

JUnit4/JUnit5

This is a test method

@TestFactory

JUnit5

Method is a JUnit5 test factory method.

@TransactionAttribute

EJB3

Method needs transaction

@TransactionManagement

EJB3

TX managed by bean or by container

@TransactionScoped

JTA

@Transactional

JTA|Spring

Whether method needs own transaction

join existing

etc.

@Transient

JPA

Omit property from database

@UiComesAfter

MW

@UiHidden

MW

@UiLabel

MW

@Valid

SpringMVC

Command Object parameter is to be validated against its BVS annotations

@Version

JPA

Use int or date field for optimistic locking

@View

@WebServlet

Servlet

Mark object as an HTTP servlet

@XmlAccessorType

JAXB

@XmlRegistry

@XmlRootElement

JAXB

Root element of generated XML document

@XmlType

JAXB

APIs:

  1. BVS - Bean Validation Spec

  2. DSD - DeltaSpike Data

  3. EJB - Enterprise JavaBeans, EJB3

  4. Servlet - Java EE Servlet API

  5. JA - javax.annotation

  6. JAX-RS - Java API for RESTful services

  7. JAX-WS - Java API for XML Web Services

  8. JAXB - Java API for XML binding

  9. JI - javax.inject

  10. JPA - Java Persistence API

  11. JSF - JavaServer Faces

  12. JUnit - JUnit unit testing framework

  13. MW - MetaWidget dynamic-UI framework

  14. Spring - Spring Framework

How we generated the list of annotations

Just grabbed all the annotations used in some code bases we have! Some funky Shell commands which will only be intelligible to the Unix cognoscenti; if that’s not you please ignore this section!

#!/bin/sh

egrep -hr '^[ \t]*@' {TicketManorJava/*,j??demo}/src/main/java |
		sed -e 's/^[ \t][ \t]*//' -e 's/".*")/)/' |
		tr ' ' '\n' | grep '^@' |
		sort -u

That gave an initial list, which was manually edited into AsciiDoc format and formatted using AsciiDoctor-pdf. Then the process was repeated on a larger set of files, and we’re still merging those into this document…​