org.zodiac.autoconfigure.web.ReactiveHttpContextAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.web;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.config.WebFluxConfigurer;
@SpringBootConfiguration
@ConditionalOnWebApplication(type = Type.REACTIVE)
@ConditionalOnClass(value = {org.springframework.web.server.WebHandler.class, org.springframework.web.reactive.DispatcherHandler.class})
public class ReactiveHttpContextAutoConfiguration implements WebFluxConfigurer {
private final HttpContextProperties httpContextProperties;
public ReactiveHttpContextAutoConfiguration(HttpContextProperties httpContextProperties) {
this.httpContextProperties = httpContextProperties;
}
@Override
public void configurePathMatching(org.springframework.web.reactive.config.PathMatchConfigurer configurer) {
/*请求路径添加统一前缀*/
String basePath = httpContextProperties.getBasePath();
configurer.addPathPrefix(basePath, c -> (c.isAnnotationPresent(Controller.class) || c.isAnnotationPresent(RestController.class)));
}
}