How do you implement dependency injection in Java EE?
Use CDI and @Inject to wire beans in Java EE and Jakarta EE. This guide covers constructor injection, qualifiers, scopes, producers and EJB integration.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
Use CDI and @Inject to wire beans in Java EE and Jakarta EE. This guide covers constructor injection, qualifiers, scopes, producers and EJB integration.
@Consumes sets which request media types a JAX-RS method accepts and @Produces sets what it returns. See content negotiation, status codes and jakarta.ws.rs.
JAX-RS has no built-in CORS support. Use a pre-matching filter to answer preflights and return CORS headers only for trusted origins.
@RolesAllowed restricts a class or method to callers in given security roles. See how to enable and use it in JAX-RS, Jersey and Spring.
Learn how to secure JAX-RS services with authentication filters, SecurityContext, role-based access, JWT and HTTPS using the current Jakarta REST API.
ExceptionMapper converts exceptions thrown by Jakarta REST (JAX-RS) resources into consistent HTTP responses. See examples, selection rules and good practice.
Map Java exceptions to clean HTTP responses in JAX-RS with ExceptionMapper, covering custom exceptions, validation and a Throwable fallback.
@QueryParam binds URL query string values to JAX-RS and Jakarta REST resource method parameters, with type conversion, defaults and support for repeated values.
Read filter and sort options from query parameters, validate them against an allow-list and apply them with streams or database queries in a JAX-RS resource.
@Path maps a URI to a JAX-RS resource class or method. Learn how paths combine, how templates and regular expressions work, and the jakarta.ws.rs package.
Build a REST API with JAX-RS and Jersey using the jakarta.ws.rs namespace, JSON via Jackson, an embedded Grizzly server and exception mappers.
@Transactional gives MongoDB multi-document ACID transactions in Spring only with a MongoTransactionManager bean and a replica set. Setup, rollback rules and pitfalls.
Configure a replica set and MongoTransactionManager, then use @Transactional for multi-document ACID transactions in Spring Boot.
Build MongoDB aggregation pipelines with $match, $group, $sort and $lookup, first in mongosh and then in Java with the official driver builders.
@MongoEntity belongs to Quarkus MongoDB with Panache and sets the collection, database and client of an entity. Spring Data MongoDB uses @Document instead.
Create a Spring Data MongoDB repository with @Document and MongoRepository, add derived and @Query methods, paging, and tests with Testcontainers.
MongoTemplate is the central Spring Data MongoDB API for CRUD, queries and aggregations. See what it does and when to prefer it over repositories.
Build a Spring Boot and MongoDB app with Spring Data: configuration, document mapping, repositories, pagination, MongoTemplate aggregation and a Testcontainers test.
Pass a Pageable to repositories or NativeQuery, sort on keyword fields, and use search_after for deep paging past 10,000 hits.
@Query lets a Spring Data Elasticsearch repository method run a hand-written JSON Query DSL search, with placeholders and paging, when derived names fall short.