org.zodiac.autoconfigure.apidoc.swagger.SwaggerAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.apidoc.swagger;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
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.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.zodiac.apidoc.swagger.EnableSwaggerMvc;
import org.zodiac.autoconfigure.application.ApplicationInfoProperties;
@EnableSwaggerMvc
@SpringBootConfiguration
@ConditionalOnWebApplication(type = Type.SERVLET)
//@ImportPropertySource(value = "classpath:/META-INF/config/swagger.yml")
@com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j
@ConditionalOnClass(value = {org.zodiac.apidoc.swagger.config.SwaggerInfo.class})
public class SwaggerAutoConfiguration extends AbstractSwaggerConfiguration implements WebMvcConfigurer {
private DefaultListableBeanFactory defaultListableBeanFactory;
public SwaggerAutoConfiguration(ApplicationInfoProperties applicationInfoProperties,
ObjectProvider openApiExtensionResolverProvider, BeanFactory beanFactory) {
super(applicationInfoProperties, openApiExtensionResolverProvider.getIfAvailable());
this.defaultListableBeanFactory = (DefaultListableBeanFactory)beanFactory;
}
@Bean
protected springfox.documentation.spring.web.plugins.Docket api(SwaggerProperties swaggerProperties) {
return super.api(swaggerProperties);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry){
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
// /*配置knife4j 显示文档 */
// registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
/*配置swagger-ui显示文档*/
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
/** 公共部分内容 */
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
// List docketList = super.apiList(swaggerProperties);
// if (CollectionUtils.isEmpty(docketList))
// return;
// for (springfox.documentation.spring.web.plugins.Docket docket : docketList) {
// Springs.registerBean(defaultListableBeanFactory, createBeanName(docket.getGroupName()), springfox.documentation.spring.web.plugins.Docket.class);
// }
}
private String createBeanName(String groupName) {
return String.format("ApiDecryptParamResolver", groupName);
}
}