swaggerconfig.java下载_如何导入Swagger Config [关闭]

Background

我遇到了一些Swagger配置问题,所以我试图通过复制一些简单的示例配置来修复它们 .

他们有这个:

@Configuration

@EnableSwagger2

public class SwaggerConfig {

@Bean

public Docket api() {

return new Docket(DocumentationType.SWAGGER_2)

.select()

.apis(RequestHandlerSelectors.any())

.paths(PathSelectors.any())

.build();

}

}

Setup

我以前在我的_2534402中有这个bean Docket但是它们似乎在自己的类中有配置 . 我想匹配他们的设置,所以我在与Application.java相同的位置创建了一个SwaggerConfiguration.java文件 .

然后我让SwaggerConfiguration.java包含以下代码:

@Configuration

@EnableSwagger2

public class SwaggerConfiguration {

@Bean

public Docket Api() {

return new Docket(DocumentationType.SWAGGER_2)

.select()

.apis(RequestHandlerSelectors.any())

.paths(PathSelectors.any())

.build()

.pathMapping("/")

.apiInfo(apiInfo());

}

private ApiInfo apiInfo() {

return new ApiInfoBuilder()

.title("Service API")

.build();

}

}

我的Application.Java包含以下代码:

@SpringBootApplication

@EnableTransactionManagement

@EnableSwagger2

@ComponentScan({"myproject.request"})

public class Application {

public static void main(String[] args) {

new SpringApplication(Application.class).run(args);

}

}

Question: 如何将此SwaggerConfiguration.java绑定到我的项目中? (导入它)

他们在这里做到了我相信:"Import the bean by adding the package name (if it’s missing) in the component-scan tag of the existing rest-dispatcher-servlet.xml" - http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api

但是,我没有那个serverlet,也没有除了maven的pom.xml之外的任何xml文件 .

Question Rephrased

我的SwaggerConfig.java只是坐在我的项目中,但没有被任何东西使用或导入 . apiInfo 例如没有在Swagger UI上设置任何内容 . 我该如何使用它 .

UPDATE 1

有人建议删除 @ComponentScan({"myproject.request"}) ,但是当我的构建失败并打印出来时:

Description:

Field actionRepository in myproject.service.ActionServiceImpl required a bean of type 'myproject.repository.ActionRepository' that could not be found.

Action:

Consider defining a bean of type 'myproject.repository.ActionRepository' in your configuration.

UPDATE 2

我已将SwaggerConfiguration更改为SwaggerConfig

@Configuration

@EnableSwagger2

public class SwaggerConfig {

/*

@Bean

public Docket Api() {

return new Docket(DocumentationType.SWAGGER_2).select()

.apis(RequestHandlerSelectors.basePackage("myproject.controller")).paths(regex("/api/*"))

.build().apiInfo(apiInfo());

}

*/

@Bean

public Docket Api() {

return new Docket(DocumentationType.SWAGGER_2)

.select()

.apis(RequestHandlerSelectors.basePackage("ibm.controller"))

.paths(regex("/api/*"))

.build()

.pathMapping("/")

.apiInfo(apiInfo());

}

private ApiInfo apiInfo() {

return new ApiInfoBuilder()

.title("Service API")

.description("API for Service REST operations")

}

}

但我有同样的问题

UPDATE 3 more background

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值