首先到GitHub上下载swagger前端页面,然后把其中的dist拿到resources下面。并在同目录下新建个swagger.properties来自定义URL:springfox.documentation.swagger.v2.path=/miniprogram。
然后修改dist的index.html,把SwaggerUIBundle参数url替换成自定义的URL。
接着在建个swagger的package来放两个自定义类
@EnableSwagger2
@Configuration
@PropertySource("classpath:swagger/swagger.properties") //引入swagger.properties
public class ApiConfig extends InterceptorConfig {
    @Profile({"test", "dev", "prod"})
    @Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(new ApiInfoBuilder()
						.title("微信小程序后台")
						.description("该服务下包含多个模块,developed by xubingtao。")
						.version("1.0")
						.build())
				.select()
				.apis(RequestHandlerSelectors.basePackage("cn.xubingtao.backend.miniprogram.controller"))
				.paths(PathSelectors.any())
				.build();
	}
}@Configuration
public class InterceptorConfig extends WebMvcConfigurerAdapter {
    /**
     *  映射url
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/miniprogram/**")
                .addResourceLocations("classpath:/swagger/dist/");
    }
}其中ApiConfig.java直接把之前的启动信息拿过来,InterceptorConfig.java映射URL,注意ApiConfig要继承InterceptorConfig,然后可以把之前引入的implementation “io.springfox:springfox-swagger-ui:2.9.2″注释掉,我这里是用gradle,你们用maven的话去pom.xml里注释。

然后重启一下就可以访问了(URL除自定义的字符串还要加上/index.html),原来的路径已经访问不了了。

展开阅读全文
上一篇: 记一次springboot项目加logback日志管理在Jenkins上gradle构建项目报Logback configuration error detected错误
下一篇:【转载】Docker 容器入门


 扫码打开小程序可评论文章保存图片,在“我的”有实时在线客服哦,
扫码打开小程序可评论文章保存图片,在“我的”有实时在线客服哦,
 关注我的公众号为您分享各类有用信息
关注我的公众号为您分享各类有用信息 分享录多端跨平台系统
分享录多端跨平台系统 粤公网安备 44011202001306号
粤公网安备 44011202001306号