背景如何导入扬鞭配置
我遇到了一些扬鞭配置的问题,所以我想通过复制一些简单的例子的CONFIGS解决这些问题。
我阅读本教程: http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
而且他们有这样的:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
设置
我曾经有过这个bean案在我public class Application
但他们似乎有在它自己的类中的配置。我想匹配它们的设置,所以我在与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);
}
}
问题:如何配合这个SwaggerConfiguration.java进入我的项目? (导入)
他们这样做是在这里,我相信:“进口豆在现有的休息 - 调度 - servlet.xml中的组件扫描标签添加软件包的名称(如果缺少)” - http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
但是,我没有那个serverlet,也没有任何xml文件,除了maven的pom.xml。
问题转述
我SwaggerConfig.java只是坐在我的项目,但不使用或进口被任何东西。例如apiInfo
未在Swagger UI上设置任何内容。我如何使用它。
更新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.
更新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个背景
这个问题在一定程度上依赖于这个问题Swagger no longer finds API controllers
取出后再次尝试'@ComponentScan({ “myproject.request”})'中的应用。注释'@ SpringBootApplication'应该处理所有这些。 –
@LucianovanderVeekens看到我的更新1 – Rorschach