-
Notifications
You must be signed in to change notification settings - Fork 41.2k
@SpringBootTest does not use spring.main.web-application-type properties declared in test resource files #29169
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
I just ran into this issue. Looks like I may not be able to update my code base to Spring Boot 2.6! |
@mat-mik (or @fdimauro) I'm having some trouble replicating the problem. I've created a sample application at https://github.com/philwebb/scratch-gh-29169, but I can't get the test to fail. Can you try and modify the sample so that it fails in the way that you describe? |
Hi @philwebb! Thank you for looking at this issue, I submitted Pull Request to your branch - philwebb/scratch-gh-29169#1 I found out that dependency should be |
Reopening after review by @mbhave where it was pointed out that by creating another |
Uh oh!
There was an error while loading. Please reload this page.
Affects versions:
2.5.7+
I believe this is result of moving this line, see details below.
Our Spring Boot application has explicit dependency to
spring-boot-starter-webflux
and transitive dependency tospring-boot-starter-web
, but intest/resources/application.properties
we declared:and we've got test:
Please note:
(1)
is important to declarewebEnvironment
because if effectively createsAbstractBeanFactory.scopes
empty. That's important because of Respect WebApplicationType.REACTIVE in tests with a mock web environment #29170(2)
we try to inject someservlet
component, we expectnull
Running such tests will fail, because Spring will try to define conflicting beans:
org.springframework.boot.web.servlet.error.DefaultErrorAttributes
(fromErrorMvcAutoConfiguration
)org.springframework.boot.web.reactive.error.DefaultErrorAttributes
(fromErrorWebFluxAutoConfiguration
)Such tests correctly passes on
2.5.6
.Mentioned change effectively changes what will be assigned here:
spring-boot/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java
Line 332 in 7c45313
Before change it was
StandardEnvironment
, after change it isApplicationServletEnvironment
. Difference changes evaluation (fromfalse
totrue
) in:spring-boot/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnWebApplicationCondition.java
Lines 138 to 140 in 7c45313
And this messes with type of web application:
The text was updated successfully, but these errors were encountered: