---
title: "Discussion on \"Spring Security's SecurityContext get unexpectedly cleared in a MockMvc Test\" | Hashnode"
description: "Discussion on \"Spring Security's SecurityContext get unexpectedly cleared in a MockMvc Test\". Background\nAt work, there’s some test written where I wanted to query the database (repository) after mockMvc request has been made to verify the result. This is a very simple illustration of what it looks like.\n@SpringBootTest\n@AutoConfigureMockMvc\n..."
url: "https://hashnode.com/posts/spring-securitys-securitycontext-get-unexpectedly-cleared-in-a-mockmvc-test/684d27cc0d5d97c6512ef455"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Spring Security's SecurityContext get unexpectedly cleared in a MockMvc Test](https://bwgjoseph.com/spring-securitys-securitycontext-get-unexpectedly-cleared-in-a-mockmvc-test?utm_source=hashnode&utm_medium=feed)

Background At work, there’s some test written where I wanted to query the database (repository) after mockMvc request has been made to verify the result. This is a very simple illustration of what it looks like. @SpringBootTest @AutoConfigureMockMvc ...

Jun 14, 2025 · 3 min read · bwgjoseph.com  
Read the article

-   [#spring-security](https://hashnode.com/tag/spring-security)
-   [#springboot](https://hashnode.com/tag/springboot)
-   [#java](https://hashnode.com/tag/java)
-   [#spring-framework](https://hashnode.com/tag/spring-framework)

## Written by

[Joseph Gan](https://hashnode.com/@bwgjoseph)

@bwgjoseph · Singapore

  
[View profile](https://hashnode.com/@bwgjoseph)

Advocate for better developer's productivity and experience Documenting my learnings and sharing it

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
