小编use*_*119的帖子

Springboot swagger url 显示 WhiteLabel 错误页面

这是我的代码:我从 application.properties 文件 SwaggerConfig.java 获取所有值

@Configuration
@EnableSwagger2
@Profile("!prod")
@PropertySource(value = { "classpath:application.properties" })
public class SwaggerConfig {

    @Value("${swagger.api.title}")
    private String title;

    @Value("${swagger.api.description}")
    private String description;

    @Value("${swagger.api.termsOfServiceUrl}")
    private String termsOfServiceUrl;

    @Value("${swagger.api.version}")
    private String version;

    @Value("${swagger.api.controller.basepackage}")
    private String basePackage;


    @Bean
    public Docket postMatchApi() {
        return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.ant("/**")).build().apiInfo(metaData());
    }

    private ApiInfo metaData() {
        return new ApiInfoBuilder().title(title).description(description).termsOfServiceUrl(termsOfServiceUrl)
                .version(version).build();
    }
Run Code Online (Sandbox Code Playgroud)

这是我的 springboot 初始化程序:

@SpringBootApplication
@ComponentScan(basePackages = { "com.example.demo" })
@ComponentScan(basePackageClasses = {AppInitializer.class, SwaggerConfig.class})
@EnableAsync
@EnableRetry
public class AppInitializer{

    public static void main(String[] args) { …
Run Code Online (Sandbox Code Playgroud)

java spring gradle spring-boot

7
推荐指数
6
解决办法
2万
查看次数

标签 统计

gradle ×1

java ×1

spring ×1

spring-boot ×1