All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.autoconfigure.web.ServletHttpContextAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
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.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootConfiguration
@ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnClass(value = {javax.servlet.Servlet.class, org.springframework.web.servlet.DispatcherServlet.class})
public class ServletHttpContextAutoConfiguration implements WebMvcConfigurer {

    private final HttpContextProperties httpContextProperties;

    public ServletHttpContextAutoConfiguration(HttpContextProperties httpContextProperties) {
        this.httpContextProperties = httpContextProperties;
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        /*请求路径添加统一前缀。*/
        String basePath = httpContextProperties.getBasePath();
        configurer.addPathPrefix(basePath, c -> (c.isAnnotationPresent(Controller.class) || c.isAnnotationPresent(RestController.class)));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy