
How to Prevent CSRF in Spring and Jakarta Apps Correctly
Stop cross-site request forgery with Spring Security's CSRF tokens, SameSite cookies and Origin checks, and know when a stateless API can skip the token.
Tag
223 posts

Stop cross-site request forgery with Spring Security's CSRF tokens, SameSite cookies and Origin checks, and know when a stateless API can skip the token.

Cut Testcontainers overhead: static containers, the singleton pattern, Spring context caching, local reuse and cleaning state between tests.

Implement distributed locks in Java: why a JVM lock is not enough, Redis and database options, lease expiry, fencing tokens and when to avoid locks entirely.

Use Hibernate ORM with Panache in Quarkus: active record and repository styles, queries, paging and transactions, with Dev Services as the database.

Run JUnit 5 from Gradle: useJUnitPlatform, dependencies with the BOM, test filtering, logging, parallel forks, tags and reports for CI.

Read large JDBC result sets without running out of memory: setFetchSize, streaming cursors in PostgreSQL and MySQL, and transaction needs.

Bind application.yml values to typed Java records with @ConfigurationProperties: prefixes, nested objects, lists, durations, defaults and relaxed names.

Enforce package and module boundaries in Java with ArchUnit rules and Spring Modulith's verify, so architecture decisions fail the build instead of drifting.

Use SpringBootTest without slow suites: share contexts, avoid DirtiesContext, trim the context, use slices and share containers.

Implement the saga pattern in Java: choreography versus orchestration, compensating actions, persisted state and failure handling.

Use Hibernate Reactive in Quarkus with Mutiny: the Uni and Multi return types, reactive Panache, transactions and when blocking ORM is the better choice.

Write parameterized tests in JUnit 5 with ParameterizedTest, ValueSource, NullSource, EnumSource and a display name, and know when a table is clearer.