问题在于你的傲慢。您只能通过以下方式选择API的一个子集(源于JPA存储库或源于RestController):
.paths(PathSelectors.regex("/api.*"))
我复制了您的场景,并注释了路径选择,我可以看到这两种类型的api。请注意,还可以使用自定义谓词来选择路径:
@Configuration
@Import({SpringDataRestConfiguration.class})
public class SwaggerConfig {
@Autowired
@SuppressWarnings({"UnusedDeclaration"})
private ServletContext servletContext;
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.pathProvider(relativePath())
.select()
.apis(RequestHandlerSelectors.any())
// .paths(paths2())
.build();
}
// Select only a few
private Predicate<String> paths2() {
return and(
(regex("/fixing.*")),
(regex("/api.*")));
}
// Exclude these
private Predicate<String> paths() {
return and(
not(regex("/error.*")),
not(regex("/metrics.*")),
not(regex("/jolokia.*")),
not(regex("/health.*")),
not(regex("/env.*")),
not(regex("/metrics.*")),
not(regex("/info.*")),
not(regex("/mappings.*")),
not(regex("/trace.*")),
not(regex("/dump.*")),
not(regex("/heapdump.*")),
not(regex("/configprops.*")),
not(regex("/beans.*")),
not(regex("/autoconfig.*")),
not(regex("/logfile.*")),
not(regex("/shutdown.*")),
not(regex("/actuator.*")));
}
}
@CrossOrigin
@RestController
@RequestMapping("/fixing")
public class FixingController {
/**
* Builds a list of Fixing strings from the database
* @return list
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public List<String> getAllFixingsViaRestController() {
final List<String> fixingList = new ArrayList<>();
fixingList.add("foo");
fixingList.add("bar");
return fixingList;
}
}
现在我的大摇大摆的用户界面是这样的;您可以看到JPA存储库贡献的REST API和RestController贡献的API(/fixing path):