能进knife4j的页面但是扫不到打了注解的接口

zzz... 发布于 2021/07/14 16:15
阅读 1K+
收藏 0

1.依赖


<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>knife4j-spring-boot-starter</artifactId>
    <version>2.0.7</version>
</dependency>

 

2.knife4j配置

@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {
    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("MOM接口文档")
                        .description("swagger knife4j测试")
                        .termsOfServiceUrl("http://www.baidu.com/")
                        .contact("zhizhizhi")
                        .version("1.0")
                        .build())
                //分组名称
                .groupName("2.X版本")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}

3.oauth2.0配置资源放行:

http
        .apply(config)
        .and()
        .csrf().disable()
        .requestMatchers().antMatchers("/**")
        .and().authorizeRequests()
        .antMatchers("/oauth/token", "/error", "/exceptioncode/api",
                "/**/swagger-ui.html",
                "/swagger-ui.html",
                "/**/doc.html",
                "/doc.html",
                "/v2/api-docs", // swagger api json
                "/v2/api-docs-ext",
                "/swagger-resources/configuration/ui", // 用来获取支持的动作
                "/swagger-resources", // 用来获取api-docsURI
                "/swagger-resources/configuration/security", // 安全选项
                "/swagger-resources/**",
                "/webjars/**").permitAll()
        .antMatchers(anonymousUrls.toArray(new String[0])).anonymous()
        .anyRequest().authenticated();

4.controller里的注解

@Slf4j
@RestController
@RequestMapping("/problemPool")
@Api(value = "改善池")
public class ProblemPoolController {
    @Autowired
    ProblemPoolService problemPoolService;

    @GetMapping("/list")
    @ApiOperation(value = "向客人问好")
    public PageResult<ProblemPoolVO> list(OmProblemPoolRequest omProblemPoolRequest, int pageIndex, int pageSize) {
        PageRequest pageRequest = PageUtil.of(pageIndex, pageSize);
        return problemPoolService.list(omProblemPoolRequest, pageRequest);
    }

5.页面上没有接口信息

加载中
0
f
freezingsky

你先用swagger,如果没问题,knife4j就没问题

0
osc_22806957
osc_22806957
@Api(tags= "改善池")  这个写法吧
0
osc_76790401
osc_76790401

作者你好,请问你解决了吗

0
osc_76790401
osc_76790401

我是,这里Controller路径写错了

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部
返回顶部
顶部