-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Setting management port causes multiple Tomcat instances to start in tests #2798
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
Comments
Well, web integration test does start the server so that makes sense to me. What if you want to test something related to a management endpoint anyway? What if you don't see the value at all? Do you expect the management stuff not to be started either? It all sounds to me that you have to have |
Thanks for the response. My expectation was that a server should never be started when using What doesn't make sense to me is that "normally" a Tomcat is never started when writing tests with just |
Just to clarify, I am still wondering if a Tomcat is supposed to start when you do not specify |
It's a bug I'd say. |
A related problem is that if you build a war file with
I believe the solution in both cases is to only start up the child context when the current web application context is an |
That doesn't work as, even when deployed to a servlet container as a war, the current web application context is still an |
Great! Thanks for the quick response. |
Prior to this commit, EndpointWebMvcAutoConfiguration would start a child context if the management port was different to the server port and the application context was a web application context. This caused two problems: If a user built an executable war and configured the management port so that it was different to the server port, their application would run successfully when launched with java -jar, but it would fail when deployed to Tomcat as an attempt would be made to start embedded Tomcat. Secondly, if a user ran a test annotated with @WebAppConfiguration the main embedded Tomcat instance would not be started, but the child context would trigger the creation of a Tomcat instance listening on the configured management port. This is unexpected as @WebIntegrationTest or @IntegrationTEST and @WebAppConfiguration should be required to have the test trigger full startup of the application and listen on the configured ports. This commit updates EndpointWebMvcAutoConfiguration so that it will only start a child context when the management port is different to the server port and the EmbeddedWebApplicationContext has an embedded servlet container. This resolves the two problems described above as there will be no embedded servlet container when deployed to a standalone container or when a test is run without @IntegrationTEST. Fixes spring-projectsgh-2798
Extract @ConditionalOnEnabledEndpoint to a top level class. See gh-2798
If I set the management port via configuration then a Tomcat will be started listening on that port when running
@WebAppConfiguration
tests.I.e. an
application.yml
with:would cause a Tomcat to start on port 8081 when running a test looking like this:
This is not the intended behavior if I am correct or am I missing something?
The implication I am running into (this might be a separate issue) is that if I have two tests with different application contexts then that will cause the second test to fail. Apparently because the loading of the second application context also tries to start a Tomcat on the same port. Which obviously fails.
That is, if the second test looks like:
then running both
ATest
andBTest
will fail one of them.So I guess the two questions are
I put some example code that illustrates this here https://github.com/sawano/spring-boot-management-port-test-issue
The text was updated successfully, but these errors were encountered: