Skip to content

Commit e806646

Browse files
committed
Broaden ConditionalOnClass checks for Web MVC
Expand the @ConditionalOnClass list in ConditionalOnWebMvcAvailable to include ApplicationContext, WebApplicationInitializer and EnableWebMvcExtension alongside Servlet and DispatcherServlet. This makes the conditional check more robust by requiring presence of core Servlet API, Spring Context, Spring Web initializer, Spring Web MVC and the Microsphere Web MVC extension APIs. Also adds corresponding imports and switches the annotation to a multi-line value with explanatory comments.
1 parent 9542a50 commit e806646

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

microsphere-spring-boot-webmvc/src/main/java/io/microsphere/spring/boot/webmvc/autoconfigure/condition/ConditionalOnWebMvcAvailable.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717

1818
package io.microsphere.spring.boot.webmvc.autoconfigure.condition;
1919

20+
import io.microsphere.spring.webmvc.annotation.EnableWebMvcExtension;
2021
import jakarta.servlet.Servlet;
2122
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2223
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2324
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
25+
import org.springframework.context.ApplicationContext;
26+
import org.springframework.web.WebApplicationInitializer;
2427
import org.springframework.web.servlet.DispatcherServlet;
2528
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
2629

@@ -46,7 +49,13 @@
4649
@Retention(RUNTIME)
4750
@Documented
4851
@ConditionalOnWebApplication(type = SERVLET)
49-
@ConditionalOnClass({Servlet.class, DispatcherServlet.class, EnableWebMvc.class})
52+
@ConditionalOnClass(value = {
53+
Servlet.class, // Servlet API
54+
ApplicationContext.class, // Spring Context API
55+
WebApplicationInitializer.class, // Spring Web API
56+
DispatcherServlet.class, // Spring Web MVC API
57+
EnableWebMvcExtension.class // Microsphere Spring Web MVC API
58+
})
5059
@ConditionalOnProperty(name = MICROSPHERE_SPRING_BOOT_WEBMVC_ENALBED_PROPERTY_NAME, matchIfMissing = true)
5160
public @interface ConditionalOnWebMvcAvailable {
5261
}

0 commit comments

Comments
 (0)