New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SpringBootTest AutoConfigureMockMvc issue with config manager not found via SessionExpiryFilter #3322
Comments
Thanks for your reporting. Normally, to make it work with Spring MVC
So if it doesn't work by default in a mocked environment, you'd need to assign a mockServletContext.setAttribute(ConfigManager.CONFIG_MANAGER, new ConfigManager()); Please try it and let us know if it works. |
It seems like Spring's I'm not seeing a way to configure the ServletContext before this happens if using the annotation. Removing Your first suggestion of SpringHawtioContextListener needing to be initialized seems like something to try but I wasn't seeing how I'd tie in the contextInitialized call. I think these workaround are good enough for me so I'm okay with closing the issue. If you think Thank you. |
Thank you for your feedback. Glad that you found a workaround. If you don't mind, let's keep the issue open and later we'll investigate the issue a bit more with your reproducer to see if there's any room for improvement from the Hawtio side. |
Hi @tadayosi & @KalCramer , I'm just working on upgrading our microservices to Spring Boot 3. We waited especially for the hawtio-springboot library to support it (v4.0) and are facing the exact same issue as described here - tests with MockMVC are failing as it cannot be started.
I am trying to implement the suggestions above but it seesm that there is no way to do it before it fails. Thanks, |
I searched Spring Boot and Spring Framework source code, but I didn't see any example or place where I checked your example and I see that So, as @tadayosi said, you need to add this attribute on your own. I checked different methods and the best one I could find in ~1 hour search is in this PR: KalCramer/spring-playground#1. When you want listeners (and SCIs) you can't use MVC mocks - you need something more :) |
Thanks @grgrzybek I eventually did the following:
The code is inspierd by Spring's In our case (lots of test classes from different git repos) - this was the simplest to deploy on all of the code repositories. Thanks, Omri |
Thanks for your solution - Spring has many customization mechanisms ;) |
Hello,
I am trying out hawtio-springboot using the following pom dependency.
When running in a basic springboot app things starting up fine and I'm able to hit the endpoint and see the UI
However, I have a simple SpringBootTest configured with AutoConfigureMockMvc and I get the following error when the SessionExpiryFilter gets called:
I'm able to add a configuration to the
AutoConfigureMockMvc
ofaddFilters = false
to workaround this but was wondering if I'm doing something wrong in initiating hawtio for this test or if this is by design.Here is a simple project with similar test that fails.
The text was updated successfully, but these errors were encountered: