Skip to content

WebApplicationType does not consider modules when deduced from classpath #48517

@matthew-js-porter

Description

@matthew-js-porter

When using an application that is using spring-boot-starter-webclient and NOT spring-boot-starter-webflux
@ConditionalOnWebApplication is evaluating to true when it should be false duirng @SpringBootTest runs.
It does not appear to be the case on normal application runs.

Steps to Reproduce

  1. Go to https://start.spring.io/
  2. Select Spring Boot 4.0.0 and add Reactive HTTP Client dependencies only.
  3. Generate the project.
  4. Add the following test code:
package com.example.conditional_on_web_demo;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

@SpringBootTest
class ConditionalOnWebDemoApplicationTests {

	@Configuration
	@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
    static class MyServletConfiguration {
	}

	@Configuration
	@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
	static class MyReactiveConfiguration {
	}

	@Configuration
	@ConditionalOnWebApplication
	static class MyGenericWebConfiguration {
	}

	@Test
	void contextLoads(
			@Autowired(required = false) MyServletConfiguration myServletConfiguration,
			@Autowired(required = false) MyReactiveConfiguration myReactiveConfiguration,
			@Autowired(required = false) MyGenericWebConfiguration myGenericWebConfiguration
	) {
		assertAll(
				() -> assertThat(myServletConfiguration).isNull(),
				() -> assertThat(myReactiveConfiguration).isNull(),
				() -> assertThat(myGenericWebConfiguration).isNull()
		);
	}
}
  1. Run the Test and observe the assertion errors (servlet will pass, reactive and generic will fail)

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions