org.zodiac.autoconfigure.knife4j.ServletKnife4jAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.knife4j;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@SpringBootConfiguration
@ConditionalOnWebApplication(type = Type.SERVLET)
@ComponentScan(basePackages = {"com.github.xiaoymin.knife4j.spring.plugin"})
@ConditionalOnProperty(name = "knife4j.enable", havingValue = "true")
@EnableConfigurationProperties(value = {com.github.xiaoymin.knife4j.spring.configuration.Knife4jProperties.class})
@ConditionalOnClass(value = {com.github.xiaoymin.knife4j.core.extend.OpenApiExtendSetting.class, com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver.class})
public class ServletKnife4jAutoConfiguration implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry){
/*配置knife4j 显示文档 */
//registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("api.html").addResourceLocations("classpath:/META-INF/resources/");
/** 公共部分内容 */
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}