How do you implement token validation in Spring Boot?
Use Spring Security's resource server to verify JWT signature, expiry, issuer and audience, map claims to roles, and write a custom filter only if needed.
2,881 posts about Java: questions with answers, tutorials and articles, newest first.
Use Spring Security's resource server to verify JWT signature, expiry, issuer and audience, map claims to roles, and write a custom filter only if needed.
See how @RequestBody binds login and registration JSON in Spring Boot authentication, with validation, AuthenticationManager and JWT token issuing.
Generate and verify signed JWTs in Spring Boot 3 using the current JJWT 0.12 API, a safely stored secret, a login endpoint and Spring Security validation.
jjwt simplifies creating and verifying JWTs in Java and Spring Boot. This guide uses the current 0.12 API and covers keys, expiry and security practices.
Register a WebMvcConfigurer for global CORS, and add a CorsConfigurationSource when Spring Security is present. This guide covers credentials, wildcards and debugging preflight requests.
HTTP method annotations only select the verb. See how paths, headers and the Spring Framework 7 version attribute turn them into versioned endpoints.
Use one controller per API version with path, header or media type routing, shared services and per-version DTOs, plus the built-in versioning in Spring Framework 7.
Use @RequestMapping to version a Spring API by path, header, parameter or media type. Compare strategies and see Spring Framework 7 built-in versioning.
MockMvc sends simulated HTTP requests to Spring MVC controllers and checks the responses without a running server. Learn setup, assertions and when to use alternatives.
Use @WebMvcTest and MockMvc to test controllers without a server. See GET and POST examples, jsonPath assertions, validation, security and full-context tests.
@TestPropertySource overrides Spring properties in a test with property files or inline values, taking precedence over application.properties and the environment.
Write Spring Boot integration tests with @SpringBootTest, MockMvc and a Testcontainers database, and learn when to choose slice tests instead.
@MockBean replaced Spring beans with Mockito mocks in tests. It is deprecated, so learn how to migrate to @MockitoBean and keep tests fast.
Use @Mock and @InjectMocks for fast unit tests, and @MockitoBean when a Spring context needs a fake bean. Includes stubbing, verify and captors.
Write a fast JUnit test for a Spring Boot service using Mockito mocks and assertions, without starting the Spring context. Includes parameterized tests and slice tests.
Add spring-boot-starter-test, then pick plain Mockito tests, WebMvcTest, DataJpaTest or SpringBootTest depending on the layer you want to verify.
The Page interface holds one page of query results plus metadata such as total elements and total pages. See how it works, when to use Slice instead, and how to expose it from a controller.
Use Pageable and Page in a Spring Boot 3 controller to serve sorted, paginated JSON, with page size limits and tips for large tables.
Use JpaRepository, Pageable and Sort to page and order data in a Spring Boot 3 REST API, with limits, Slice and stable JSON output.
There is no @ErrorView annotation in Spring. See how to map errors to custom views with error templates, ErrorViewResolver and @ControllerAdvice.